エンジニアを目指す初学者に向けて、わかりやすく解説したブログです。

ClaudeDesktopとNotion MCPを連携するときの詰まったポイント

ゴール

https://notion.notion.site/Notion-MCP-1d0efdeead058054a339ffe6b38649e1 を参考に、ClaudeとNotionを連携する。

基本的にはNotionの記事通りに進めるが、詰まったポイントがあるので記事として書いておく。

結論

ポイントは2つ。

  1. jsonのエスケープ
  2. PATHを通す
{
  "mcpServers": {
    "notionApi": {
      "timeout": 60,
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer <ntn_から始まるnotionのトークン>\", \"Notion-Version\":\"2022-06-28\" }",
        "PATH": "<echo $PATHして出力された値>"
      }
    }
  }
}

①jsonのエスケープ

対象の記事では、ダブルクウォートのエスケープに \\ を使っているが、正しくは \ を使う。

{
  "mcpServers": {
    "notionApi": {
      "command": "npx",
      "args": [
        "-y",
        "@notionhq/notion-mcp-server"
      ],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer ntn_****************************\", \"Notion-Version\":\"2022-06-28\" }"
      }
    }
  }
}

②パスを通す

筆者は fnmを使ってnodeのバージョン管理を行っている。

このようなバージョン管理ツールを使っている場合、Claudeからnpxコマンドやnodeコマンドを実行したときにエラーが発生する。

エラーの例

Image in a image block
MCP notionApi: spawn npx ENOENT
Could not connect to MCP server notionApi
MCP notionApi: Server disconnected. For troubleshooting guidance, please visit our debugging documentation

ログファイルである mcp-server-notionApi.logには以下のように出力されている。

2025-04-12T02:20:42.060Z [notionApi] [info] Initializing server...
2025-04-12T02:20:42.093Z [notionApi] [info] Server started and connected successfully
2025-04-12T02:20:42.094Z [notionApi] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
env: node: No such file or directory
2025-04-12T02:20:42.100Z [notionApi] [info] Server transport closed
2025-04-12T02:20:42.100Z [notionApi] [info] Client transport closed
2025-04-12T02:20:42.100Z [notionApi] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-04-12T02:20:42.100Z [notionApi] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
2025-04-12T02:20:42.101Z [notionApi] [info] Client transport closed

解決策

envに環境変数 PATHを追加して、 echo $PATHをした結果をそのまま入れる。

{
  "mcpServers": {
    "notionApi": {
      "timeout": 60,
      "command": "npx",
      "args": ["-y", "@notionhq/notion-mcp-server"],
      "env": {
        "OPENAPI_MCP_HEADERS": "{\"Authorization\": \"Bearer <ntn_から始まるnotionのトークン>\", \"Notion-Version\":\"2022-06-28\" }",
        "PATH": "<echo $PATHして出力された値>"
      }
    }
  }
}

調べると、npxコマンドの方をフルパスで設定するような記事が出てくるが
内部で呼び出されているnodeコマンドでも似たような事象が発生してしまうので、シンプルにPATHを追加するのが良い。

動作確認

チャットに新しいアイコンが追加されていれば、MCPサーバーの設定は完了している。

Image in a image block

質問をしてみると、筆者がNotionにメモしたWebサイトなどが検索され、出力される。

Image in a image block