Skip to content

Commit 8e356f6

Browse files
chelojimenezclaude
andcommitted
Add sample tool, prompt, and resource for educational demo
Registers three new MCP primitives using the standard SDK methods (contrasting with the existing ext-apps wrappers): - greet tool: simple name → greeting - explain-concept prompt: parameterized message template - server-info resource: static plain-text server overview Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8378a8c commit 8e356f6

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/index.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,84 @@ export class MyMCP extends McpAgent {
6565
],
6666
}),
6767
);
68+
69+
// ── Sample Tool (standard SDK method) ─────────────────────────
70+
// Contrast with registerAppTool above: no UI resource, just I/O.
71+
this.server.tool(
72+
"greet",
73+
"Returns a friendly greeting for the given name",
74+
{
75+
name: z.string().describe("The name of the person to greet"),
76+
},
77+
async ({ name }) => ({
78+
content: [
79+
{
80+
type: "text" as const,
81+
text: `Hello, ${name}! Welcome to the MCP App Demo server.`,
82+
},
83+
],
84+
}),
85+
);
86+
87+
// ── Sample Prompt ─────────────────────────────────────────────
88+
// Prompts are reusable message templates that clients can discover
89+
// and fill in with parameters.
90+
this.server.prompt(
91+
"explain-concept",
92+
"Generates a prompt asking for a clear explanation of a concept",
93+
{
94+
concept: z.string().describe("The concept or topic to explain"),
95+
audience: z
96+
.enum(["beginner", "intermediate", "expert"])
97+
.describe("Target audience level"),
98+
},
99+
async ({ concept, audience }) => ({
100+
description: `Explain "${concept}" for a ${audience} audience`,
101+
messages: [
102+
{
103+
role: "user" as const,
104+
content: {
105+
type: "text" as const,
106+
text:
107+
`Please explain the concept of "${concept}" ` +
108+
`in a way that is appropriate for a ${audience}-level audience. ` +
109+
`Use clear language, relevant examples, and keep it concise.`,
110+
},
111+
},
112+
],
113+
}),
114+
);
115+
116+
// ── Sample Resource ───────────────────────────────────────────
117+
// Resources expose read-only data that clients can fetch by URI.
118+
this.server.resource(
119+
"server-info",
120+
"info://mcp-demo/server-info",
121+
{
122+
description: "General information about this MCP demo server",
123+
mimeType: "text/plain",
124+
},
125+
async (uri) => ({
126+
contents: [
127+
{
128+
uri: uri.href,
129+
mimeType: "text/plain",
130+
text:
131+
"MCP App Demo Server v1.0.0\n" +
132+
"==========================\n\n" +
133+
"This is an educational MCP server demonstrating the three core primitives:\n\n" +
134+
"1. Tools – Functions the client can invoke (e.g., 'greet', 'display-mcp-app')\n" +
135+
"2. Prompts – Reusable message templates (e.g., 'explain-concept')\n" +
136+
"3. Resources – Read-only data the client can fetch (e.g., this document)\n\n" +
137+
"Built with:\n" +
138+
" - @modelcontextprotocol/sdk\n" +
139+
" - @modelcontextprotocol/ext-apps\n" +
140+
" - Cloudflare Workers (agents package)\n" +
141+
" - Zod for schema validation\n",
142+
},
143+
],
144+
}),
145+
);
68146
}
69147
}
70148

0 commit comments

Comments
 (0)