Skip to main content
Glama

Basic MCP Server

by gurdasnijor
index.ts2.09 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" import { z } from "zod" // Configuration schema with detailed documentation export const configSchema = z.object({ debug: z.boolean() .default(false) .describe("Enable debug logging for troubleshooting and development. When enabled, tool outputs will include DEBUG: prefix."), }) export default function createServer({ config, }: { config?: z.infer<typeof configSchema> // your server configuration (optional) }) { // Parse and validate config with defaults const validatedConfig = configSchema.parse(config || {}) const server = new McpServer({ name: "Say Hello", version: "1.0.0", icon: "icon.svg", }) // Add a tool server.registerTool( "hello", { title: "Hello Tool", description: "Say hello to someone", inputSchema: { name: z.string().describe("Name to greet") }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true } }, async ({ name }) => ({ content: [ { type: "text", text: validatedConfig.debug ? `DEBUG: Hello ${name}` : `Hello, ${name}!` // use validated config } ], }) ) // Add a resource server.registerResource( "hello-world-history", "history://hello-world", { title: "Hello World History", description: "The origin story of the famous 'Hello, World' program", }, async uri => ({ contents: [ { uri: uri.href, text: '"Hello, World" first appeared in a 1972 Bell Labs memo by Brian Kernighan and later became the iconic first program for beginners in countless languages.', mimeType: "text/plain", }, ], }), ) // Add a prompt server.registerPrompt( "greet", { title: "Hello Prompt", description: "Say hello to someone", argsSchema: { name: z.string().describe("Name of the person to greet"), }, }, async ({ name }) => { return { messages: [ { role: "user", content: { type: "text", text: `Say hello to ${name}`, }, }, ], } }, ) return server.server }

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/gurdasnijor/server-quality-harness'

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