Skip to content

MCP Server Connection Issue - SOLUTION - Firebase Studio | VSCode | Gemini #136

@heleusbrands

Description

@heleusbrands

1. Initial Problem

Environment: Firebase Studio | Cloud VSCode | Gemini | Gemini CLI

The goal was to run the @notionhq/notion-mcp-server within a VS Code cloud environment. Like many of you, several standard configurations, as suggested both here officially and in the issues section, in mcp.json were attempted but failed:

Direct npx execution: This failed with authorization errors or a generic MCP error -32000: Connection closed.

Docker execution: This was initially explored, but abandoned since it wasn't ideal for my setup.

2. Verifying the Core Command

The first step was to confirm if the npx command itself was valid. We ran it directly in the VS Code terminal:

NOTION_TOKEN="ntn_..." NOTION_API_VERSION="2022-06-28" npx -y @notionhq/notion-mcp-server

The command ran without any error output; it simply hung, waiting for input. This proved that the command, token, and API version were all correct and that the problem was specific to how the MCP extension was launching the process.

3. Investigating the Execution Environment

Since the manual command worked but the MCP configuration failed, I suspected the extension was not creating the same environment as the terminal. To investigate, I created a debug server to inspect the environment variables being passed by the extension:

"notionApi-debug": {
	"command": "env",
		"args": [],
		"env": {
			"NOTION_TOKEN": "ntn_...",
			"NOTION_API_VERSION": "..."
		}
}

4. The Key Issue

This debug server immediately failed with a revealing error in the MCP Output channel:

[warning] [MCPManager] Error from server notionApi-debug: SyntaxError - Unexpected token 'N', "NOTION_TOK"... is not valid JSON

This was the key bit of info needed. It showed that the MCP extension expects the server process to communicate strictly via JSON-RPC. When the env command printed plain text, the extension tried to parse it as JSON, failed, and closed the connection. This meant that the original npx command was also likely failing instantly and printing a plain-text error message, but that real error was being hidden behind the generic "Connection closed" message.

5. The Solution: Forcing an Identical Environment

Knowing that the manual bash command worked, the final solution was to force the MCP extension to replicate that exact execution context. I wrapped the entire working command in a bash -c "..." call.

{
	"mcpServers": {
		"notionApi": {
			"command": "bash",
			"args": [
			"-c",
			"NOTION_TOKEN='ntn_...' NOTION_API_VERSION='2022-06-28' npx -y @notionhq/notion-mcp-server"
			]
		}
	}
}

This approach bypasses any issues with how the VS Code extension handles environment variable injection or sets the PATH, ensuring the server is launched in the exact same way as the successful manual test.

Hope this helps some of you get this up and running!

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