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

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

Closed
2013xile opened this issue Dec 6, 2024 · 1 comment
Closed

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

2013xile opened this issue Dec 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@2013xile
Copy link

2013xile commented Dec 6, 2024

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.

@2013xile 2013xile added the bug Something isn't working label Dec 6, 2024
@2013xile
Copy link
Author

2013xile commented Dec 7, 2024

This workround works for me finally modelcontextprotocol/servers#64

@2013xile 2013xile closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant