@@ -10,43 +10,102 @@ Learn more: https://modelcontextprotocol.io/docs/getting-started/intro
1010
1111### Required Environment Variables
1212
13- - ** ` COCALC_API_KEY ` ** - API key for CoCalc authentication (format: ` sk-... ` )
14- - ** ` COCALC_PROJECT_ID ` ** - UUID of the target CoCalc project
13+ - ** ` COCALC_API_KEY ` ** - API key for CoCalc authentication (format: ` sk-... ` , can be account-scoped or project-scoped)
1514- ** ` COCALC_HOST ` ** (optional) - CoCalc instance URL (default: ` https://cocalc.com ` )
1615
1716### Setup Examples
1817
19- ** Local Development:**
18+ ** Local Development (Recommended: Project-Scoped API Key):**
19+
20+ Create a project-scoped API key in your CoCalc project settings:
21+
22+ ``` bash
23+ export COCALC_API_KEY=" sk-your-project-api-key-here"
24+ export COCALC_HOST=" http://localhost:5000" # For local CoCalc, or omit for cocalc.com
25+ uv run cocalc-mcp-server
26+ ```
27+
28+ When started, the server will report:
29+
30+ ```
31+ ✓ Connected with project-scoped API key (project: 6e75dbf1-0342-4249-9dce-6b21648656e9)
32+ ```
33+
34+ ** Alternative: Account-Scoped API Key:**
35+
36+ Create an account-scoped API key in your CoCalc account settings (Settings → API keys):
37+
2038``` bash
21- export COCALC_API_KEY=" sk-your-api-key-here"
22- export COCALC_PROJECT_ID=" 6e75dbf1-0342-4249-9dce-6b21648656e9"
23- export COCALC_HOST=" http://localhost:5000" # For local CoCalc
39+ export COCALC_API_KEY=" sk-your-account-api-key-here"
2440uv run cocalc-mcp-server
2541```
2642
27- ** Claude Code CLI:**
43+ When started, the server will report:
44+
45+ ```
46+ ✓ Connected with account-scoped API key (account: d0bdabfd-850e-4c8d-8510-f6f1ecb9a5eb)
47+ ```
48+
49+ ** Claude Code CLI (Project-Scoped Key - Recommended):**
50+
2851``` bash
2952claude mcp add \
3053 --transport stdio \
3154 cocalc \
32- --env COCALC_API_KEY=" sk-your-api-key-here" \
33- --env COCALC_PROJECT_ID=" 6e75dbf1-0342-4249-9dce-6b21648656e9" \
34- --env COCALC_HOST=" http://localhost:5000" \
55+ --env COCALC_API_KEY=" sk-your-project-api-key-here" \
3556 -- uv --directory /path/to/cocalc-api run cocalc-mcp-server
3657```
3758
38- ** Claude Desktop:**
59+ ** Claude Code CLI (Account-Scoped Key):**
60+
61+ ``` bash
62+ claude mcp add \
63+ --transport stdio \
64+ cocalc \
65+ --env COCALC_API_KEY=" sk-your-account-api-key-here" \
66+ -- uv --directory /path/to/cocalc-api run cocalc-mcp-server
67+ ```
68+
69+ ** Claude Desktop (Project-Scoped Key - Recommended):**
70+
3971Add to ` ~/.config/Claude/claude_desktop_config.json ` :
72+
4073``` json
4174{
4275 "mcpServers" : {
4376 "cocalc" : {
4477 "command" : " uv" ,
45- "args" : [" --directory" , " /path/to/cocalc-api" , " run" , " cocalc-mcp-server" ],
78+ "args" : [
79+ " --directory" ,
80+ " /path/to/cocalc-api" ,
81+ " run" ,
82+ " cocalc-mcp-server"
83+ ],
4684 "env" : {
47- "COCALC_API_KEY" : " sk-your-api-key-here" ,
48- "COCALC_PROJECT_ID" : " 6e75dbf1-0342-4249-9dce-6b21648656e9" ,
49- "COCALC_HOST" : " http://localhost:5000"
85+ "COCALC_API_KEY" : " sk-your-project-api-key-here"
86+ }
87+ }
88+ }
89+ }
90+ ```
91+
92+ ** Claude Desktop (Account-Scoped Key):**
93+
94+ Add to ` ~/.config/Claude/claude_desktop_config.json ` :
95+
96+ ``` json
97+ {
98+ "mcpServers" : {
99+ "cocalc" : {
100+ "command" : " uv" ,
101+ "args" : [
102+ " --directory" ,
103+ " /path/to/cocalc-api" ,
104+ " run" ,
105+ " cocalc-mcp-server"
106+ ],
107+ "env" : {
108+ "COCALC_API_KEY" : " sk-your-account-api-key-here"
50109 }
51110 }
52111 }
@@ -97,6 +156,7 @@ src/cocalc_api/mcp/
97156Execute arbitrary shell commands in the CoCalc project.
98157
99158** Parameters:**
159+
100160- ` command ` (string, required): Command to execute
101161- ` args ` (list, optional): Command arguments
102162- ` bash ` (boolean, optional): Interpret as bash script
@@ -106,6 +166,7 @@ Execute arbitrary shell commands in the CoCalc project.
106166** Returns:** stdout, stderr, and exit_code
107167
108168** Examples:**
169+
109170``` json
110171{"command" : " echo 'Hello'" }
111172{"command" : " python" , "args" : [" script.py" , " --verbose" ]}
@@ -121,6 +182,7 @@ Browse project directory structure.
121182** URI:** ` cocalc://project-files/{path} `
122183
123184** Parameters:**
185+
124186- ` path ` (string, optional): Directory path (default: ` . ` )
125187
126188** Returns:** Formatted list of files and directories
@@ -130,6 +192,7 @@ Browse project directory structure.
130192### Adding a New Tool
131193
1321941 . Create ` tools/my_tool.py ` :
195+
133196``` python
134197def register_my_tool (mcp ) -> None :
135198 """ Register my tool with FastMCP instance."""
@@ -143,6 +206,7 @@ def register_my_tool(mcp) -> None:
143206```
144207
1452082 . Update ` tools/__init__.py ` :
209+
146210``` python
147211def register_tools (mcp ) -> None :
148212 from .exec import register_exec_tool
0 commit comments