Skip to content

Commit e993068

Browse files
committed
api: add OpenAI-compatible adapter + MCP server
1 parent ee2920b commit e993068

4 files changed

Lines changed: 693 additions & 2 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
1616
RUN apt-get update && apt-get install -y \
1717
python3 python3-pip \
1818
&& rm -rf /var/lib/apt/lists/* \
19-
&& pip3 install --no-cache-dir fastapi uvicorn python-telegram-bot pyyaml
19+
&& pip3 install --no-cache-dir fastapi uvicorn python-telegram-bot pyyaml mcp
2020

2121
# docker (needed for docker-in-docker)
2222
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,79 @@ curl -X DELETE "http://localhost:8080/files/myproject/src/old.py" -H "Authorizat
500500

501501
All file paths are relative to `/workspaces`. Path traversal outside root is blocked.
502502

503+
#### OpenAI-compatible endpoints
504+
505+
The API also exposes an OpenAI-compatible adapter so tools like [LiteLLM](https://github.com/BerriAI/litellm), OpenAI SDKs, or anything that speaks `chat/completions` can connect directly.
506+
507+
**`GET /openai/v1/models`** — list available models:
508+
509+
```bash
510+
curl http://localhost:8080/openai/v1/models
511+
# {"object":"list","data":[{"id":"haiku",...},{"id":"sonnet",...},{"id":"opus",...}]}
512+
```
513+
514+
**`POST /openai/v1/chat/completions`** — chat completions (streaming and non-streaming):
515+
516+
```bash
517+
# non-streaming
518+
curl -X POST http://localhost:8080/openai/v1/chat/completions \
519+
-H "Content-Type: application/json" \
520+
-d '{"model":"haiku","messages":[{"role":"user","content":"hello"}]}'
521+
522+
# streaming
523+
curl -X POST http://localhost:8080/openai/v1/chat/completions \
524+
-H "Content-Type: application/json" \
525+
-d '{"model":"haiku","messages":[{"role":"user","content":"hello"}],"stream":true}'
526+
```
527+
528+
Use the same model aliases as the CLI (`haiku`, `sonnet`, `opus`). `system` role messages become `--system-prompt`. Multiple user/assistant turns are concatenated into a single prompt. Pass `reasoning_effort` (`low`/`medium`/`high`) to control effort — maps to claude's `--effort`. `temperature` and `max_tokens` are accepted but ignored.
529+
530+
Custom headers for claude-specific behavior:
531+
532+
| Header | Description |
533+
| ------ | ----------- |
534+
| `X-Claude-Workspace` | Workspace subpath under `/workspaces` |
535+
| `X-Claude-Continue` | Set to `1`/`true`/`yes` to continue the previous session |
536+
537+
**LiteLLM example:**
538+
539+
```python
540+
import litellm
541+
542+
response = litellm.completion(
543+
model="openai/haiku",
544+
messages=[{"role": "user", "content": "hello"}],
545+
api_base="http://localhost:8080/openai/v1",
546+
api_key="your-secret-token", # or any string if no token set
547+
)
548+
print(response.choices[0].message.content)
549+
```
550+
551+
#### MCP server
552+
553+
The API also exposes an MCP (Model Context Protocol) server at `/mcp` using streamable HTTP transport. Any MCP-compatible client (Claude Desktop, Claude Code, etc.) can connect to it.
554+
555+
```json
556+
{
557+
"mcpServers": {
558+
"claude-code": {
559+
"url": "http://localhost:8080/mcp",
560+
"headers": { "Authorization": "Bearer your-secret-token" }
561+
}
562+
}
563+
}
564+
```
565+
566+
Available tools:
567+
568+
| Tool | Description |
569+
| ---- | ----------- |
570+
| `claude_run` | Run a prompt through Claude. Params: `prompt`, `model`, `system_prompt`, `append_system_prompt`, `json_schema`, `workspace`, `no_continue`, `resume`, `effort` |
571+
| `list_files` | List files/dirs in the workspace |
572+
| `read_file` | Read a file from the workspace |
573+
| `write_file` | Write a file to the workspace |
574+
| `delete_file` | Delete a file from the workspace |
575+
503576
### Telegram mode
504577

505578
Talk to Claude from Telegram. Each chat gets its own workspace and settings. Send text, files, photos, videos, voice messages. Run shell commands. Get files back.

0 commit comments

Comments
 (0)