Skip to main content
Create one typed tool, register it on a server, and expose it over stdio. Complete installation first, including type: module and tsconfig.json. This tutorial separates the tool from the server so you can reuse it.

1. Define the tool

src/tools/greet.ts
The handler’s input type comes from the schema. A nonempty string is required; invalid input is rejected before execution. The output schema checks the returned object too.

2. Compose the server

src/server.ts
The registration key greet becomes the exposed name. A definition can be reused in another server without rewriting it. listen() starts the transport; it does not wait for the server to shut down.

3. Run it through a client

After compiling, configure your MCP client to launch node with the absolute path to dist/server.js. A stdio server speaks through stdin/stdout; running it in a terminal may appear to wait silently because it is waiting for protocol messages. Compile your application:
Then call it with Inspector:
Inspector starts the compiled server and sends this argument:
The successful result includes structured data and a text serialization:
Try invalid input to see validation feedback. The handler does not run for an empty name:
Keep stdout clean. MCP owns stdout. Send application diagnostics to stderr with console.error() rather than console.log().

Next steps

Configure a client, run the same tool over HTTP, or learn about tool definitions. The complete runnable teaching example is in apps/stdio-example.