Skip to main content
Glama
stevennevins

MCP Server Template

by stevennevins

example-tool

Processes input data to transform or analyze strings for integration within MCP server workflows. This tool handles text processing tasks within the TypeScript-based MCP Server Template framework.

Instructions

An example tool that processes input data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesInput string to process

Implementation Reference

  • Handler implementation for 'example-tool' that extracts input, validates with Zod, processes via helper function, and returns the tool result.
    'example-tool': async (request) => {
      try {
        const { input } = request.params.arguments as { input: string }
        const inputSchema = z.object({
          input: z.string().min(1, 'Input must not be empty')
        })
        inputSchema.parse({ input })
        const result = await handleExampleProcess(input)
    
        return {
          toolResult: {
            content: [{ type: 'text', text: result }],
          },
        }
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error)
        throw new Error(`Failed to process input: ${errorMessage}`)
      }
    }
  • Tool schema definition for 'example-tool' including name, description, and input schema.
    const EXAMPLE_TOOL: Tool = {
      name: 'example-tool',
      description: 'An example tool that processes input data',
      inputSchema: {
        type: 'object',
        properties: {
          input: {
            type: 'string',
            description: 'Input string to process',
            minLength: 1
          }
        },
        required: ['input']
      }
    }
  • src/index.ts:21-22 (registration)
    Combines example tools and handlers into global collections used by the MCP server for tool listing and execution.
    const ALL_TOOLS = [...EXAMPLE_TOOLS]
    const ALL_HANDLERS = { ...EXAMPLE_HANDLERS }
  • src/index.ts:31-34 (registration)
    Registers the request handler for listing available tools, which includes 'example-tool' via ALL_TOOLS.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      log('Received list tools request')
      return { tools: ALL_TOOLS }
    })
  • Helper function called by the tool handler to process the input string.
    async function handleExampleProcess(input: string): Promise<string> {
      log('Processing input:', input)
      return `Processed: ${input}`
    }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/stevennevins/mcp-server-template'

If you have feedback or need assistance with the MCP directory API, please join our Discord server