MCP Stdio Server Example

This is a basic implementation of a Model Context Protocol (MCP) server using the stdio transport. It includes a simple getPassword tool that returns "foobar" as a password.

Installation

pnpm install

Building the Project

pnpm build

Running the Server

The server is designed to be run via the client:

node dist/client.js

This will:

  1. Start the MCP server as a child process
  2. Connect a client to the server via stdio transport
  3. List available tools
  4. Call the getPassword tool to retrieve the password "foobar"
  5. Call the echo tool with a message

Server Implementation

The server implements two tools:

  • getPassword: Returns "foobar" as the password (no parameters)
  • echo: Echoes back the provided message (requires a message parameter)

Sample Output

When running the client, you should see output similar to:

Connecting to server...
Connected to server.
Listing available tools:
{
  "tools": [
    {
      "name": "getPassword",
      "description": "",
      "arguments": []
    },
    {
      "name": "echo",
      "description": "",
      "arguments": [
        {
          "name": "message",
          "description": "",
          "required": true
        }
      ]
    }
  ]
}

Calling getPassword tool:
Password: foobar

Calling echo tool:
Echo Response: You said: Hello from MCP client!
Closed connection to server.