[WIP] Refactor everything server to be more modular and use recommended APIs.

For tools where we seek to get some response from the server, renamed as an action, e.g., "Get Sum" rather than "Add" or "Get Annotated Message" rather than "Annotated Message", so that it's clear what the intent of the tool is in a quick review.

* Updated architecture.md

* Refactor/renamed add.ts to get-sum.ts
* Refactor/renamed annotated-message.ts to get-annotated-message.ts
* In tools/index.ts
  - sorted presentation order
This commit is contained in:
cliffhall
2025-12-10 16:08:41 -05:00
parent 904d0ea71f
commit f759d9eaa1
4 changed files with 29 additions and 29 deletions

View File

@@ -0,0 +1,45 @@
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
// Tool input schema
const GetSumSchema = z.object({
a: z.number().describe("First number"),
b: z.number().describe("Second number"),
});
// Tool configuration
const name = "get-sum";
const config = {
title: "Get Sum Tool",
description: "Gets the sum of two numbers",
inputSchema: GetSumSchema,
};
/**
* Registers the 'get-sum' tool with the provided McpServer instance.
**
* The registered tool processes input arguments, validates them using a predefined schema,
* calculates the sum of two numeric values, and returns the result in a content block.
*
* Expects input arguments to conform to a specific schema that includes two numeric properties, `a` and `b`.
* Validation is performed to ensure the input adheres to the expected structure before calculating the sum.
*
* The result is returned as a Promise resolving to an object containing the computed sum in a text format.
*
* @param {McpServer} server - The server instance where the sum tool will be registered.
*/
export const registerGetSumTool = (server: McpServer) => {
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
const validatedArgs = GetSumSchema.parse(args);
const sum = validatedArgs.a + validatedArgs.b;
return {
content: [
{
type: "text",
text: `The sum of ${validatedArgs.a} and ${validatedArgs.b} is ${sum}.`,
},
],
};
});
};