11# CoCalc API MCP Server
22
3- A Model Context Protocol (MCP) server that allows LLMs to interact with CoCalc projects.
3+ A Model Context Protocol (MCP) server that provides LLMs (Claude, etc.) with direct access to CoCalc accounts and projects.
44
55## Quick Start
66
7- ### 1. Configuration
8-
9- Set environment variables:
7+ ### 1. Set Environment Variables
108
119``` bash
12- export COCALC_API_KEY=" sk-your-api-key"
13- export COCALC_PROJECT_ID=" your-project-uuid"
14- export COCALC_HOST=" https://cocalc.com" # optional, defaults to https://cocalc.com
10+ export COCALC_API_KEY=" sk-your-api-key" # Account or project-scoped
11+ export COCALC_HOST=" http://localhost:5000" # Optional, defaults to https://cocalc.com
1512```
1613
1714### 2. Run the Server
@@ -20,46 +17,31 @@ export COCALC_HOST="https://cocalc.com" # optional, defaults to https://cocalc.
2017uv run cocalc-mcp-server
2118```
2219
23- ### 3. Setup with Claude Code CLI
20+ The server will detect your API key type and automatically register the appropriate tools/resources.
21+
22+ ## Setup with Claude Code
23+
24+ ### Quick Registration
2425
2526``` bash
26- # Set your credentials
27- export COCALC_API_KEY=" sk-your-api-key-here"
28- export COCALC_PROJECT_ID=" [UUID]"
29- export COCALC_API_PATH=" /path/to/cocalc/src/python/cocalc-api"
30- # OPTIONAL: set the host, defaults to cocalc.com. for development use localhost:5000
31- export COCALC_HOST=" http://localhost:5000"
32-
33- # Add the MCP server to Claude Code
3427claude mcp add \
3528 --transport stdio \
3629 cocalc \
37- --env COCALC_API_KEY=" $COCALC_API_KEY " \
38- --env COCALC_PROJECT_ID=" $COCALC_PROJECT_ID " \
39- --env COCALC_HOST=" $COCALC_HOST " \
40- -- uv --directory " $COCALC_API_PATH " run cocalc-mcp-server
30+ --env COCALC_API_KEY=" sk-your-api-key" \
31+ -- uv --directory /path/to/cocalc-api run cocalc-mcp-server
4132```
4233
43- Alternatively, using JSON configuration:
34+ ### Via JSON Config
4435
4536``` bash
4637claude mcp add-json cocalc ' {
4738 "command": "uv",
48- "args": ["--directory", "/path/to/cocalc/src/python/cocalc-api", "run", "cocalc-mcp-server"],
49- "env": {
50- "COCALC_API_KEY": "sk-your-api-key-here",
51- "COCALC_PROJECT_ID": "[UUID]",
52- "COCALC_HOST": "http://localhost:5000"
53- }
39+ "args": ["--directory", "/path/to/cocalc-api", "run", "cocalc-mcp-server"],
40+ "env": {"COCALC_API_KEY": "sk-your-api-key"}
5441}'
5542```
5643
57- ** Important:**
58-
59- - Replace ` /path/to/cocalc/src/python/cocalc-api ` with the absolute path to your cocalc-api directory.
60- - Replace ` http://localhost:5000 ` with your CoCalc instance URL (defaults to ` https://cocalc.com ` if not set).
61-
62- ### 4. Setup with Claude Desktop
44+ ## Setup with Claude Desktop
6345
6446Add to ` ~/.config/Claude/claude_desktop_config.json ` :
6547
@@ -68,111 +50,62 @@ Add to `~/.config/Claude/claude_desktop_config.json`:
6850 "mcpServers" : {
6951 "cocalc" : {
7052 "command" : " uv" ,
71- "args" : [
72- " --directory" ,
73- " /path/to/cocalc/src/python/cocalc-api" ,
74- " run" ,
75- " cocalc-mcp-server"
76- ],
77- "env" : {
78- "COCALC_API_KEY" : " sk-your-api-key-here" ,
79- "COCALC_PROJECT_ID" : " [UUID]" ,
80- "COCALC_HOST" : " http://localhost:5000"
81- }
53+ "args" : [" --directory" , " /path/to/cocalc-api" , " run" , " cocalc-mcp-server" ],
54+ "env" : {"COCALC_API_KEY" : " sk-your-api-key" }
8255 }
8356 }
8457}
8558```
8659
87- ** Important:**
88-
89- - Replace ` /path/to/cocalc/src/python/cocalc-api ` with the absolute path to your cocalc-api directory.
90- - Replace ` http://localhost:5000 ` with your CoCalc instance URL (defaults to ` https://cocalc.com ` if not set).
91-
92- ### 5. Allow MCP Tools in Claude Code Settings
60+ ## Allow Tools in Claude Code Settings
9361
94- To automatically allow all CoCalc MCP tools without prompts, add this to ` .claude/settings.json ` :
62+ Add to ` .claude/settings.json ` :
9563
9664``` json
9765{
9866 "allowedTools" : [" mcp__cocalc__*" ]
9967}
10068```
10169
102- This wildcard pattern ( ` mcp__cocalc__* ` ) automatically allows:
70+ ## Available Tools & Resources
10371
104- - ` mcp__cocalc__exec ` - Execute shell commands
105- - ` mcp__cocalc__project_files ` - Browse project files
106- - Any future tools added to the MCP server
72+ The server automatically provides different tools based on your API key type:
10773
108- ## Features
74+ ### Account-Scoped API Keys
10975
110- ### Tools
76+ ** Tools:**
77+ - ` projects_search(query="") ` - Search and list your projects with collaborator info
11178
112- - ** ` exec ` ** - Execute shell commands in the project
79+ ** Resources:**
80+ - ` cocalc://account-profile ` - View your account info, settings, and preferences
11381
114- ```
115- Tool: exec
116- Params: command (required), args, bash, timeout, cwd
117- Returns: {stdout, stderr, exit_code}
118- ```
82+ ### Project-Scoped API Keys
11983
120- - ** ` jupyter_execute ` ** - Execute code using Jupyter kernels
121- ```
122- Tool: jupyter_execute
123- Params: input (required), kernel (default: "python3"), history
124- Returns: Formatted execution output (text, plots, errors, etc.)
125- ```
84+ ** Tools:**
85+ - ` exec(command) ` - Execute shell commands in the project
86+ - ` jupyter_execute(input, kernel="python3") ` - Run code using Jupyter kernels
12687
127- ### Resources
88+ ** Resources:**
89+ - ` cocalc://project-files ` - Browse the project directory structure
12890
129- - ** ` project-files ` ** - Browse project files with filtering and pagination
130- ```
131- URI: cocalc://project-files/{path}?glob=*.py&limit=100&recurse=true
132- Returns: File listing with metadata
133- ```
91+ ## API Keys
13492
135- ## Documentation
93+ Create API keys at:
94+ - ** Account-scoped** : CoCalc Settings → API keys → Create API key
95+ - ** Project-scoped** : Project Settings → API keys → Create API key
13696
137- See [ DEVELOPMENT.md] ( ./DEVELOPMENT.md ) for:
138-
139- - Architecture and design principles
140- - Detailed API specifications
141- - Configuration options
142- - Testing strategy
143- - Future roadmap
144-
145- ## Directory Structure
146-
147- ```
148- src/cocalc_api/mcp/
149- ├── README.md # This file
150- ├── DEVELOPMENT.md # Architecture & design documentation
151- ├── server.py # Main MCP server
152- ├── mcp_server.py # MCP instance and project client coordination
153- ├── __main__.py # Module entry point
154- ├── tools/
155- │ ├── exec.py # Shell command execution tool
156- │ └── __init__.py
157- └── resources/
158- ├── file_listing.py # File listing resource
159- └── __init__.py
160- ```
161-
162- ## Requirements
97+ ## Security
16398
164- - Python 3.10+
165- - mcp>=1.0
166- - httpx
167- - pydantic (via mcp)
99+ - Never commit API keys to version control
100+ - Use restricted file permissions (600) on config files with API keys
101+ - Each server instance is isolated to its scope (account or project)
102+ - Commands execute with the permissions of your API key
168103
169- ## Security
104+ ## Development
170105
171- - API keys should never be committed to version control
172- - Use restricted file permissions (600) on config files containing API keys
173- - Each server instance is scoped to a single project
174- - Commands execute with the permissions of the CoCalc project user
106+ See [ DEVELOPMENT.md] ( ./DEVELOPMENT.md ) for architecture, design patterns, and adding new tools.
175107
176- ## Next Steps
108+ ## References
177109
178- See [ DEVELOPMENT.md] ( ./DEVELOPMENT.md#next-steps ) for implementation roadmap and upcoming features.
110+ - [ MCP Specification] ( https://modelcontextprotocol.io/ )
111+ - [ CoCalc API Documentation] ( https://github.com/sagemathinc/cocalc )
0 commit comments