#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ErrorCode,
ListToolsRequestSchema,
McpError,
ReadResourceRequestSchema,
ListResourcesRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{
name: "jiechau-mcp-vincent-says",
version: "0.1.1",
},
{
capabilities: {
tools: {},
resources: {},
},
}
);
// Add a tool to ask Vincent something
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "ask_vincent",
description: "Ask Vincent something and get a yes/no answer.",
inputSchema: {
type: "object",
properties: {
question: {
type: "string",
description: "The question to ask Vincent",
},
},
required: ["question"],
},
},
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === "ask_vincent") {
const question = args?.question;
if (typeof question !== "string") {
throw new McpError(
ErrorCode.InvalidParams,
"Question must be a string"
);
}
// Random yes/no answer like in the Python version
const answer = Math.random() < 0.5
? "yes, that's a good idea!"
: "no! hell no!";
return {
content: [
{
type: "text",
text: answer,
},
],
};
}
throw new McpError(ErrorCode.MethodNotFound, `Tool ${name} not found`);
});
// Add resources for personalized greetings
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "greeting://example",
name: "Greeting Resource Template",
description: "Get a personalized greeting. Use greeting://{name} to get a greeting for a specific name.",
mimeType: "text/plain",
},
],
};
});
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const { uri } = request.params;
const greetingMatch = uri.match(/^greeting:\/\/(.+)$/);
if (greetingMatch) {
const name = greetingMatch[1];
const greeting = `Hello, ${name}! Would you like to ask Vincent something?`;
return {
contents: [
{
uri,
mimeType: "text/plain",
text: greeting,
},
],
};
}
throw new McpError(ErrorCode.InvalidParams, `Resource not found: ${uri}`);
});
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error("Server error:", error);
process.exit(1);
});