You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project provides a Model Context Protocol (MCP) server for interacting with the [Neo4j Sandbox API](https://sandbox.neo4j.com/). It allows language models or other MCP clients to easily launch, list, query, and perform other actions on Neo4j Sandbox instances using a standardized tool interface.
6
6
7
-
The server is built as a [FastAPI](https://fastapi.tiangolo.com/) application and uses the [FastAPI-MCP](https://fastapi-mcp.tadata.com/getting-started/welcome) library to expose its endpoints as MCP tools. Authentication with the Sandbox API is handled via Auth0, and the necessary Auth0 credentials must be configured through environment variables.
7
+
The server is built as a [FastAPI](https://fastapi.tiangolo.com/) application and uses [FastMCP](https://gofastmcp.com/) (v2.12.4) to expose its endpoints as MCP tools. FastMCP provides enterprise-grade OAuth 2.1 authentication with Auth0, along with backward compatibility for API key authentication. The necessary Auth0 credentials must be configured through environment variables.
8
8
9
9
## Environment Variables
10
10
@@ -15,38 +15,44 @@ The server requires the following environment variables to be set for Auth0 auth
15
15
*`AUTH0_CLIENT_ID`: The Client ID of your Auth0 Application.
16
16
*`AUTH0_CLIENT_SECRET`: The Client Secret of your Auth0 Application.
17
17
*`SANDBOX_API_KEY`: Your Neo4j Sandbox API key. This is used by the underlying `neo4j-sandbox-api-client`.
18
+
*`PORT` (optional): The port to run the server on. Defaults to `9100` if not set.
18
19
19
20
You can set these variables directly in your environment or place them in a `.env` file in the project root.
20
21
21
22
## Running the Server
22
23
23
-
1.**Install dependencies:**
24
-
It's recommended to use a virtual environment.
24
+
1.**Install UV (if not already installed):**
25
25
```bash
26
-
python -m venv .venv
27
-
source .venv/bin/activate # On Windows use `.venv\\Scripts\\activate`
28
-
pip install -r requirements.txt
29
-
# Or using uv
30
-
# uv pip install -r requirements.txt
31
-
```
26
+
# macOS/Linux
27
+
curl -LsSf https://astral.sh/uv/install.sh | sh
32
28
33
-
2. **Set environment variables:**
34
-
Ensure the `.env` file is present in the `mcp-server` directory and populated with your Auth0 and Sandbox API credentials as described above.
Alternatively, if you have `src`in your `PYTHONPATH` or are in the `mcp-server` directory:
38
+
39
+
3. **Set environment variables:**
40
+
Ensure the `.env` file is present in the project root and populated with your Auth0 and Sandbox API credentials as described above.
41
+
42
+
4. **Run the FastAPI application:**
43
+
The server can be started using UV:
42
44
```bash
43
-
python src/sandbox_api_mcp_server/server.py
45
+
uv run sandbox-api-mcp-server
44
46
```
45
-
This will typically start the server on `http://0.0.0.0:9100`. The MCP endpoint will be available at `http://0.0.0.0:9100/sse` (as configured in`server.py`).
47
+
This will start the server on `http://0.0.0.0:9100`. The MCP server is available at two transport endpoints:
48
+
- `http://0.0.0.0:9100/sse` - SSE transport (legacy, backward compatible)
49
+
- `http://0.0.0.0:9100/mcp` - Streamable HTTP transport (modern, recommended for production)
46
50
47
51
## Using with MCP Clients (e.g., Claude Desktop)
48
52
49
-
To use this MCP server with an MCP client, you need to configure the client to connect to the running FastAPI server. Given the OAuth2 flow used for authentication, **it is highly recommended to use `mcp-remote`** to bridge the connection. `mcp-remote` will handle the browser-based login and token passing to the MCP server.
53
+
To use this MCP server with an MCP client, you need to configure the client to connect to the running FastAPI server. This server uses **FastMCP 2.12.4** to expose FastAPI endpoints as MCP tools. Authentication is handled via Auth0 (OAuth2/JWT) and API keys at the FastAPI layer.
54
+
55
+
**It is recommended to use `mcp-remote`** to bridge the connection, especially if you need to handle OAuth token acquisition. `mcp-remote` can help manage authentication tokens for the HTTP requests to the server.
50
56
51
57
### Step 1: Install `mcp-remote` (if not already installed)
52
58
@@ -57,27 +63,37 @@ npm install -g mcp-remote
57
63
58
64
### Step 2: Run your FastAPI MCP Server
59
65
60
-
Ensure your FastAPI MCP server is running locally (e.g., on `http://localhost:9100` with the MCP endpoint at `http://localhost:9100/sse`):
61
-
```bash
62
-
python src/sandbox_api_mcp_server/server.py
63
-
```
64
-
Or using uvicorn directly:
66
+
Ensure your FastAPI MCP server is running locally (e.g., on `http://localhost:9100`):
- `http://localhost:9100/sse` - SSE transport (backward compatible)
73
+
- `http://localhost:9100/mcp` - Streamable HTTP transport (recommended)
74
+
69
75
70
76
### Step 3: Run `mcp-remote`
71
77
72
-
In a new terminal, start `mcp-remote`, pointing it to your local MCP server's `/sse` endpoint and choosing a local port for`mcp-remote` to listen on (e.g., `8080`):
78
+
In a new terminal, start `mcp-remote`, pointing it to your local MCP server. You can choose either transport endpoint:
73
79
80
+
**Using SSE (legacy, backward compatible):**
74
81
```bash
75
82
# If mcp-cli is installed globally
76
83
mcp-remote http://localhost:9100/sse 8080
77
84
78
85
# Or using npx
79
86
npx -y mcp-remote http://localhost:9100/sse 8080
80
87
```
88
+
89
+
**Using Streamable HTTP (modern, recommended):**
90
+
```bash
91
+
# If mcp-cli is installed globally
92
+
mcp-remote http://localhost:9100/mcp 8080
93
+
94
+
# Or using npx
95
+
npx -y mcp-remote http://localhost:9100/mcp 8080
96
+
```
81
97
`mcp-remote` will now listen on `localhost:8080` and proxy requests to your actual MCP server, handling the OAuth flow.
**Option B: Using Streamable HTTP transport (recommended):**
127
+
```json
128
+
{
129
+
"mcpServers": {
130
+
"neo4j-sandbox-mcp-via-remote": {
131
+
"command": "npx",
132
+
"args": [
133
+
"-y",
134
+
"mcp-remote",
135
+
"http://localhost:9100/mcp",
136
+
"8080"
137
+
]
138
+
}
139
+
}
140
+
}
141
+
```
108
142
**Note:** With `mcp-remote` handling the connection to your actual server and its authentication, the Claude Desktop configuration becomes simpler, primarily needing to know where `mcp-remote` is accessible.
109
143
110
144
3. **Restart Claude Desktop:**
@@ -244,9 +278,60 @@ The following tools are exposed, derived from the FastAPI application's endpoint
244
278
245
279
## Development
246
280
281
+
### Project Structure
282
+
247
283
* The main FastAPI application logic is in`src/sandbox_api_mcp_server/server.py`.
248
284
* API routes (which become MCP tools) are defined in`src/sandbox_api_mcp_server/sandbox/routes.py`.
249
285
* Request/response models are primarily in`src/sandbox_api_mcp_server/sandbox/models.py` and `src/sandbox_api_mcp_server/models.py`.
250
286
* Authentication logic is in`src/sandbox_api_mcp_server/auth.py`.
251
-
* The project uses `uv` for dependency management (see `uv.lock`) and `pip` for installation (`requirements.txt`).
252
-
* Consider using `hatch` or `poetry` for more robust dependency management and packaging if distributing this server. (The `pyproject.toml` suggests `hatch` might be intended for future use).
- Supports `Authorization: Bearer ApiKey <key>` header format
322
+
- Maintained in FastAPI routes via `Depends(verify_auth)`
323
+
- Ensures existing API consumers continue to work
324
+
325
+
**Note on MCP OAuth Support:**
326
+
Future versions may implement native MCP OAuth support via `OAuthAuthorizationServerProvider`, which would provide Dynamic Client Registration (DCR) compliance and seamless OAuth flows specifically designed for the MCP protocol. The current implementation leverages FastMCP's ability to convert FastAPI endpoints while maintaining the existing FastAPI authentication system.
327
+
328
+
### FastMCP Features
329
+
330
+
This server leverages [FastMCP 2.12.4](https://www.jlowin.dev/blog/fastmcp-2-12) features:
331
+
332
+
- **FastAPI Integration**: Seamless conversion of FastAPI endpoints to MCP tools via `FastMCP.from_fastapi()`
333
+
- **Route Filtering**: Excludes internal endpoints (like `/health`) from MCP tool exposure using `RouteMap` configurations
334
+
- **Authentication Compatibility**: Works with existing FastAPI authentication middleware (Auth0 JWT + API keys)
335
+
- **Dual Transport Support**: Provides both transport protocols for maximum compatibility
336
+
- **SSE** at `/sse` - Legacy transport for backward compatibility with existing clients
337
+
- **Streamable HTTP** at `/mcp` - Modern transport recommended for production deployments
0 commit comments