feat(examples): transform hono-mcp server to Vengabus party theme

Transform the generic example server into a fun Vengabus-themed MCP server with:
- Replace generic tools with party-themed tools (party capacity calculator, vengabus schedule)
- Update resources to use party-themed URIs and content
- Replace generic prompts with party invitations and announcements
- Fix resource URI handling to strip trailing slashes
- Fix TypeScript errors with proper resource template typing
- Use docs:// protocol for party manual resource

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jem 2025-07-02 18:24:03 -07:00
commit 6a42f9dc93

View file

@ -1,4 +1,4 @@
import { McpServer, type ReadResourceTemplateCallback, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js' import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StreamableHTTPTransport } from '@hono/mcp' import { StreamableHTTPTransport } from '@hono/mcp'
import { Hono } from 'hono' import { Hono } from 'hono'
import { z } from 'zod' import { z } from 'zod'
@ -17,19 +17,27 @@ app.use(
// Your MCP server implementation // Your MCP server implementation
const mcpServer = new McpServer({ const mcpServer = new McpServer({
name: 'my-mcp-server', name: 'vengabus-mcp-server',
version: '1.0.0', version: '1.0.0',
}) })
mcpServer.registerTool( mcpServer.registerTool(
'add', 'calculate_party_capacity',
{ {
title: 'Addition Tool', title: 'Party Bus Capacity Calculator',
description: 'Add two numbers', description: 'Calculate how many people can fit on the Vengabus',
inputSchema: { a: z.number(), b: z.number() }, inputSchema: {
busCount: z.number().describe('Number of Vengabuses'),
peoplePerBus: z.number().describe('People per bus'),
},
}, },
async ({ a, b }) => ({ async ({ busCount, peoplePerBus }) => ({
content: [{ type: 'text', text: String(a + b) }], content: [
{
type: 'text',
text: `🚌 ${busCount} Vengabuses can transport ${busCount * peoplePerBus} party people! The wheels of steel are turning! 🎉`,
},
],
}), }),
) )
@ -48,7 +56,22 @@ mcpServer.registerTool(
content: [ content: [
{ {
type: 'text', type: 'text',
text: `Next Vengabus: imminent. Current user's route: New York to San Francisco. Route name: "Intercity Disco".`, text: `🚌 BOOM BOOM BOOM BOOM! Next Vengabus: IMMINENT! 🎉
Current Route: "Intercity Disco Express"
From: New York
To: IBIZA - THE MAGIC ISLAND! ✨
Schedule:
- Departure: When the beat drops
- Via: San Francisco (quick party stop)
- Arrival: When the sun comes up
Status: The party bus is jumping!
Passengers: Maximum capacity!
BPM: 142 and rising!
We're going to Ibiza! Back to the island! 🏝️`,
}, },
], ],
} }
@ -58,107 +81,124 @@ mcpServer.registerTool(
// Register sample resources // Register sample resources
mcpServer.registerResource( mcpServer.registerResource(
'config', 'config',
'config://app', 'config://vengabus',
{ {
title: 'Application Configuration', title: 'Vengabus Fleet Configuration',
description: 'Current application configuration settings', description: 'Current Vengabus fleet settings and party parameters',
mimeType: 'application/json', mimeType: 'application/json',
}, },
async (uri: URL) => ({ async (uri: URL) => {
contents: [ const normalizedUri = uri.href.replace(/\/$/, '')
{ return {
uri: uri.href, contents: [
mimeType: 'application/json', {
text: JSON.stringify( uri: normalizedUri,
{ mimeType: 'application/json',
version: '1.0.0', text: JSON.stringify(
environment: 'test', {
features: { version: '1.0.0',
vengabus: true, fleet: 'intercity-disco',
calculator: true, features: {
bassBoost: true,
strobeEnabled: true,
maxBPM: 160,
wheelsOfSteel: 'turning',
},
routes: ['New York to Ibiza', 'Back to the Magic Island', 'Like an Intercity Disco', 'The place to be'],
}, },
}, null,
null, 2,
2, ),
), },
}, ],
], }
}), },
) )
mcpServer.registerResource( mcpServer.registerResource(
'readme', 'readme',
'file://readme.md', 'docs://party-manual.md',
{ {
title: 'README', title: 'Vengabus Party Manual',
description: 'Server documentation', description: 'Official guide to the Vengabus experience',
mimeType: 'text/markdown', mimeType: 'text/markdown',
}, },
async (uri: URL) => ({ () => ({
contents: [
{ contents: [
uri: uri.href, {
mimeType: 'text/markdown', uri: 'docs://party-manual.md',
text: '# Test MCP Server\n\nThis is a test server for the use-mcp integration tests.\n\n## Features\n- Addition tool\n- Vengabus schedule checker\n- Sample resources\n- Sample prompts', mimeType: 'text/markdown',
}, text: "# 🚌 Vengabus MCP Server\n\nBOOM BOOM BOOM BOOM! Welcome aboard the Vengabus! We like to party!\n\n## Features\n- 🎉 Party capacity calculator - How many can we take to Ibiza?\n- 🕐 Vengabus schedule checker - Next stop: The Magic Island!\n- 🎵 Fleet configuration with maximum bass boost\n- 🌟 Party statistics tracker (BPM, passengers, energy levels)\n\n## Routes\n- New York to Ibiza (via San Francisco)\n- Back to the Magic Island\n- Like an Intercity Disco\n- The place to be\n\n## Current Status\nThe wheels of steel are turning, and traffic lights are burning!\nWe're going to Ibiza! Woah! We're going to Ibiza!\n\n*Up, up and away we go!*",
], }
]
}), }),
) )
// Register a resource template // Register a resource template
mcpServer.registerResource( mcpServer.registerResource(
'stats', 'stats',
new ResourceTemplate('data://stats/{type}', { list: undefined }), new ResourceTemplate('party://stats/{metric}', { list: undefined }),
{ {
title: 'Statistics Data', title: 'Vengabus Party Statistics',
description: 'Get statistics for different types', description: 'Get party metrics (bpm, passengers, energy)',
mimeType: 'application/json', mimeType: 'application/json',
}, },
// @ts-expect-error - type is missing in the callback async (uri: URL, { metric }) => {
async (uri: URL, { type }) => ({ return {
contents: [ contents: [
{ {
uri: uri.href, uri: uri.href,
mimeType: 'application/json', mimeType: 'application/json',
text: JSON.stringify( text: JSON.stringify(
{ {
type: type, metric: metric,
count: Math.floor(Math.random() * 100), value:
lastUpdated: new Date().toISOString(), metric === 'bpm'
}, ? 140 + Math.floor(Math.random() * 20)
null, : metric === 'passengers'
2, ? Math.floor(Math.random() * 50) + 20
), : metric === 'energy'
}, ? Math.floor(Math.random() * 100)
], : 0,
}), unit:
metric === 'bpm'
? 'beats per minute'
: metric === 'passengers'
? 'party people'
: metric === 'energy'
? 'party power %'
: 'unknown',
status: 'The party is jumping!',
lastUpdated: new Date().toISOString(),
},
null,
2,
),
},
],
}
},
) )
// Register sample prompts // Register sample prompts
mcpServer.registerPrompt( mcpServer.registerPrompt(
'greeting', 'party_invitation',
{ {
title: 'Generate Greeting', title: 'Vengabus Party Invitation',
description: 'Generate a greeting message', description: 'Generate a party invitation for the Vengabus',
argsSchema: { argsSchema: {
name: z.string().describe('Name of the person to greet'), name: z.string().describe('Name of the party person'),
style: z.string().optional().describe('Style of greeting (formal/casual)'), destination: z.string().optional().describe('Where the Vengabus is heading'),
}, },
}, },
({ name, style }) => ({ ({ name, destination }) => ({
messages: [ messages: [
{ {
role: 'user', role: 'user',
content: { content: {
type: 'text', type: 'text',
text: `Generate a ${style || 'casual'} greeting for ${name}`, text: `Create a party invitation for ${name} to join the Vengabus${destination ? ` heading to ${destination}` : ''}`,
},
},
{
role: 'assistant',
content: {
type: 'text',
text: style === 'formal' ? `Good day, ${name}. I hope this message finds you well.` : `Hey ${name}! How's it going?`,
}, },
}, },
], ],
@ -166,22 +206,22 @@ mcpServer.registerPrompt(
) )
mcpServer.registerPrompt( mcpServer.registerPrompt(
'code_review', 'party_announcement',
{ {
title: 'Code Review Template', title: 'Party Bus Announcement',
description: 'Template for code review requests', description: 'Generate party-themed announcements for various occasions',
argsSchema: { argsSchema: {
language: z.string().describe('Programming language'), event: z.string().describe('Type of event (deployment, release, milestone, etc.)'),
focus: z.string().optional().describe('What to focus on (performance/security/style)'), details: z.string().optional().describe('Additional details about the event'),
}, },
}, },
({ language, focus }) => ({ ({ event, details }) => ({
messages: [ messages: [
{ {
role: 'user', role: 'user',
content: { content: {
type: 'text', type: 'text',
text: `Please review the following ${language} code${focus ? ` with a focus on ${focus}` : ''}:`, text: `Create a party bus announcement for a ${event}${details ? `: ${details}` : ''}`,
}, },
}, },
], ],