Skip to content

"Could not attach to MCP server" error on MacOS Claude Desktop #86

@2013xile

Description

@2013xile

Describe the bug
A clear and concise description of what the bug is.

I used the script in the README.md to write a demo on MacOS

#!/usr/bin/env node

import {Server} from '@modelcontextprotocol/sdk/server/index.js';
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';
import {
  ListResourcesRequestSchema,
  ReadResourceRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';

// Server setup
const server = new Server(
  {
    name: 'mcp-server-nocobase',
    version: '1.0.0',
  },
  {
    capabilities: {
      resources: {},
    },
  },
);

server.setRequestHandler(ListResourcesRequestSchema, async () => {
  return {
    resources: [
      {
        uri: 'file:///example.txt',
        name: 'Example Resource',
      },
    ],
  };
});

server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
  if (request.params.uri === 'file:///example.txt') {
    return {
      contents: [
        {
          uri: 'file:///example.txt',
          mimeType: 'text/plain',
          text: 'This is the content of the example resource.',
        },
      ],
    };
  } else {
    throw new Error('Resource not found');
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);

And I configure claude_desktop_config.json

{
  "mcpServers": {
    "demo": {
      "command": "node",
      "args": [
        "/Users/xile/code/mcp-server-demo/build/index.js"
      ]
    }
  }
}

When I restarted the Claude Desktop, it occurred an error "Could not attach to MCP server demo".

I had also try npm link and set

{
  "mcpServers": {
    "demo": {
      "command": "npx",
      "args": [
        "mcp-server-demo"
      ]
    }
  }
}

To Reproduce
Steps to reproduce the behavior:
1.

Expected behavior
A clear and concise description of what you expected to happen.

It is expected to work when using Claude desktop on MacOS.

Logs
If applicable, add logs to help explain your problem.

mcp.log showed

2024-12-06T21:01:51.571Z [info] Attempting to connect to MCP server demo...
2024-12-06T21:01:51.578Z [info] Connected to MCP server demo!

mcp-server-demo.log showed nothing.

Additional context
Add any other context about the problem here.

The project works well when using @modelcontextprotocol/inspector

I had followed some other issues like modelcontextprotocol/servers#40 and try to fix the issue, but none of them works for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions