Skip to content

MCP server disconnects / URL returns Unauthorized #4

Closed

Description

@robdodson

I followed the tutorial video from this article but I think I may have missed something.
https://blog.cloudflare.com/model-context-protocol/

My index.ts looks like this:

import { WorkerEntrypoint } from 'cloudflare:workers';
import { ProxyToSelf } from 'workers-mcp';

export default class MyWorker extends WorkerEntrypoint<Env> {
	/**
	 * A warm, friendly greeting from your new Workers MCP server.
	 * @param name {string} the name of the person we are greeting.
	 * @return {string} the contents of our greeting.
	 */
	sayHello(name: string) {
		return `Hello from an MCP Worker, ${name}!`;
	}

	/**
	 * @ignore
	 **/
	async fetch(request: Request): Promise<Response> {
		return new ProxyToSelf(this).fetch(request);
	}
}

And my claude_desktop_config.json looks like this:

{
  "mcpServers": {
    "image-gen-mcp": {
      "command": "/Users/my_user_name/Developer/my-mcp/node_modules/.bin/workers-mcp",
      "args": [
        "run",
        "my-mcp",
        "https://my-mcp.my-subdomain.workers.dev",
        "/Users/my_user_name/Developer/my-mcp"
      ],
      "env": {}
    }
  }
}

When I start Claude I get an error saying the MCP server disconnected. When I try to visit the URL for the MCP on my subdomain it just says "Unauthorized".

I was wondering if this was possibly related to the SHARED_SECRET that gets created? I tried adding it to the env section of Claude's MCP config but that didn't seem to fix it.

Activity

  1. robdodson commented on Jan 4, 2025

    @robdodson
    Author

    Looking in Claude's log file for my MCP server (found at ~/Library/Logs/Claude), it looks like there might be something wrong with the build:

    file:///Users/my-username/Developer/my-mcp/node_modules/workers-mcp/dist/cli.js:574
    import { scheduler } from "node:timers/promises";
             ^^^^^^^^^
    SyntaxError: The requested module 'node:timers/promises' does not provide an export named 'scheduler'
        at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
        at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
        at async Promise.all (index 0)
        at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
        at async loadESM (node:internal/process/esm_loader:88:5)
        at async handleMainPromise (node:internal/modules/run_main:65:12)
    
  2. robdodson commented on Jan 5, 2025

    @robdodson
    Author

    It looks like Claude was creating a non-interactive shell which doesn't load .zshrc, so nvm was not being initialized correctly. Claude was using an older version of node from nvm, v16, which doesn't have scheduler in node:timers/promises. I "fixed" the issue by just deleting node 16, which leaves only node 20 in my list of nvm versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions