Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MCP inspector connection with TypeScript SDK server #135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ server.resource(
}]
})
);

// Connect to a transport
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const transport = new StdioServerTransport();
await server.connect(transport);
Comment on lines +76 to +77
Copy link

@tpina tpina Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const transport = new StdioServerTransport();
await server.connect(transport);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
};
// invoke main method
main().catch((error) => {
console.error("Fatal error in main():", error);
process.exit(1);
});

```

## What is MCP?
Expand Down Expand Up @@ -385,7 +390,6 @@ const client = new Client(
resources: {},
tools: {}
}
}
);

await client.connect(transport);
Expand All @@ -410,6 +414,58 @@ const result = await client.callTool("example-tool", {
});
```

## Running Your Server

### Development Mode

To run your server in development mode, you can use the following command:

```bash
npm run dev
```

This will start your server with hot-reloading enabled, so any changes you make to your code will automatically restart the server.

### Claude Desktop Integration

To integrate your server with Claude Desktop, follow these steps:

1. Install Claude Desktop from the official website.
2. Configure Claude Desktop to connect to your MCP server by specifying the server's address and port.
3. Start your MCP server and ensure it is running.
4. Launch Claude Desktop and verify the connection to your MCP server.

### Direct Execution

To run your server directly, use the following command:

```bash
node dist/index.js
```

This will start your server using the compiled JavaScript files in the `dist` directory.

### Running with MCP Inspector

To run your server with the MCP Inspector, follow these steps:

1. Install the MCP Inspector globally using npm:
```bash
npm install -g @modelcontextprotocol/inspector
```

2. Start your MCP server:
```bash
npm run start
```

3. In a separate terminal, start the MCP Inspector and connect it to your running server:
```bash
npx @modelcontextprotocol/inspector npm run -s start
```

This will start the MCP Inspector and connect it to your running server, allowing you to inspect and interact with your server's resources, tools, and prompts.

## Documentation

- [Model Context Protocol documentation](https://modelcontextprotocol.io)
Expand Down