← Back to Dashboard
1. Prompt Templates2. Dynamic Arguments3. Context Assembly

Context Assembly

📚 Prompts⏱ 8 min⭐ 90 XP⌨ Hands-on lab

Injecting Resources into Prompts

The ultimate power of an MCP Prompt is assembling vast amounts of context before the conversation even starts. Inside your prompt function, you can load external Resource data.

server.prompt(
  "onboard_developer",
  {},
  async () => {
    // Dynamically assemble context
    const architecture = await fs.readFile('architecture.md');
    return {
      messages: [{
        role: "user",
        content: {
          type: "text",
          text: `Here is the team architecture: ${architecture}\n\nPlease explain the build process.`
        }
      }]
    };
  }
);

This pattern ensures the LLM is perfectly grounded with absolute truth before the user asks their first question.

⌨ HANDS-ON LABAssemble Multi-Resource Context Prompt
⭐ +150 XP

Combine prompt instructions with embedded resource attachments in a prompts/get response.

1Call prompts/get for review_logs to inspect assembled multi-resource context.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
Why might you read files dynamically inside a Prompt function?
To validate the file system.
To inject massive blocks of accurate, up-to-date context into the LLM prompt.
To compress network traffic.
You cannot read files in a Prompt function.