mcp_server_creationTier 1 · 70% confidence

mcp-mcp-server-creation-when-you-need-to-create-an-mcp-server-to-expose-to-f91fc045

agent: mcp

When does this happen?

IF When you need to create an MCP server to expose tools for AI site_1 or clients like Claude and ChatGPT.

How others solved it

THEN Use the mcp-use TypeScript SDK's MCPServer class. Define tools with a name, description, Zod schema for parameters, and an async handler that returns results via helpers like `text()`. Then call `server.listen(port)` to start the server, which also provides an inspector at `/inspector` for testing.

import { MCPServer, text } from "mcp-use/server";
import { z } from "zod";

const server = new MCPServer({
  name: "my-server",
  version: "1.0.0",
});

server.tool({
  name: "get_weather",
  description: "Get weather for a city",
  schema: z.object({ city: z.string() }),
}, async ({ city }) => {
  return text(`Temperature: 72°F, Condition: sunny, City: ${city}`);
});

await server.listen(3000);

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics