openai-compatible-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openai_compatible_mcp-0.1.0/LICENSE +21 -0
- openai_compatible_mcp-0.1.0/PKG-INFO +252 -0
- openai_compatible_mcp-0.1.0/README.md +228 -0
- openai_compatible_mcp-0.1.0/pyproject.toml +42 -0
- openai_compatible_mcp-0.1.0/setup.cfg +4 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp/__init__.py +8 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp/__main__.py +178 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp/client.py +205 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp/server.py +161 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/PKG-INFO +252 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/SOURCES.txt +14 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/dependency_links.txt +1 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/entry_points.txt +2 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/requires.txt +3 -0
- openai_compatible_mcp-0.1.0/src/openai_compatible_mcp.egg-info/top_level.txt +1 -0
- openai_compatible_mcp-0.1.0/tests/test_unit.py +114 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openai-compatible-mcp contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openai-compatible-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server that bridges to any OpenAI-compatible chat API (DeepSeek, OpenAI, Azure, local llama.cpp, etc.).
|
|
5
|
+
Author: openai-compatible-mcp contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Source, https://github.com/xiaobaotalks/openai-compatible-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/xiaobaotalks/openai-compatible-mcp/issues
|
|
9
|
+
Keywords: mcp,model-context-protocol,openai,deepseek,llm,chat
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# openai-compatible-mcp
|
|
26
|
+
|
|
27
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that
|
|
28
|
+
bridges to any **OpenAI-compatible chat API** — DeepSeek, OpenAI, Azure OpenAI,
|
|
29
|
+
OpenRouter, Together, Groq, local llama.cpp, and friends.
|
|
30
|
+
|
|
31
|
+
> **Default provider:** DeepSeek. Switch to any OpenAI-compatible endpoint with
|
|
32
|
+
> a single environment variable.
|
|
33
|
+
|
|
34
|
+
The server runs over **stdio** (the standard MCP transport) and exposes two
|
|
35
|
+
tools that any MCP-compatible client can call:
|
|
36
|
+
|
|
37
|
+
- **`chat`** — send a chat completion, get the assistant's reply
|
|
38
|
+
- **`list_models`** — show the configured default model and friendly aliases
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- Zero third-party dependencies (Python 3.9+ stdlib only)
|
|
43
|
+
- Works with **any** OpenAI-compatible chat API
|
|
44
|
+
- Friendly model aliases (`deepseek-v4-flash` → `deepseek-chat`, `r1` → `deepseek-reasoner`, etc.)
|
|
45
|
+
- Optional reasoning content extraction (DeepSeek-R1 style)
|
|
46
|
+
- Built-in JSON-RPC 2.0 over stdio MCP transport
|
|
47
|
+
- Tiny: ~400 lines of code
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
### 1. Install
|
|
52
|
+
|
|
53
|
+
From source:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/xiaobaotalks/openai-compatible-mcp.git
|
|
57
|
+
cd openai-compatible-mcp
|
|
58
|
+
pip install -e .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or run directly without installing:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
PYTHONPATH=src python -m openai_compatible_mcp
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Configure
|
|
68
|
+
|
|
69
|
+
Set your API key and (optionally) the base URL:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# DeepSeek (default)
|
|
73
|
+
export DEEPSEEK_API_KEY="sk-..."
|
|
74
|
+
|
|
75
|
+
# OpenAI
|
|
76
|
+
export OPENAI_API_KEY="sk-..."
|
|
77
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://api.openai.com"
|
|
78
|
+
|
|
79
|
+
# Azure OpenAI
|
|
80
|
+
export OPENAI_COMPATIBLE_MCP_API_KEY="..."
|
|
81
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://YOUR-RESOURCE.openai.azure.com/openai/deployments/YOUR-DEPLOYMENT"
|
|
82
|
+
|
|
83
|
+
# Local llama.cpp server
|
|
84
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="http://127.0.0.1:8080"
|
|
85
|
+
export OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL="llama-3.1-8b"
|
|
86
|
+
|
|
87
|
+
# Custom: anything speaking the OpenAI /v1/chat/completions protocol
|
|
88
|
+
export OPENAI_COMPATIBLE_MCP_API_KEY="..."
|
|
89
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://my.example.com"
|
|
90
|
+
export OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL="my-model"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Environment variable lookup order (first one set wins):
|
|
94
|
+
|
|
95
|
+
| Setting | Variables tried (in order) |
|
|
96
|
+
| ------------- | -------------------------------------------------------------------------------- |
|
|
97
|
+
| API key | `OPENAI_COMPATIBLE_MCP_API_KEY` → `DEEPSEEK_API_KEY` → `OPENAI_API_KEY` |
|
|
98
|
+
| Base URL | `OPENAI_COMPATIBLE_MCP_BASE_URL` → `DEEPSEEK_API_BASE` → `OPENAI_BASE_URL` |
|
|
99
|
+
| Default model | `OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL` → `DEEPSEEK_DEFAULT_MODEL` |
|
|
100
|
+
|
|
101
|
+
### 3. Wire it up to an MCP client
|
|
102
|
+
|
|
103
|
+
#### Claude Desktop
|
|
104
|
+
|
|
105
|
+
`~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
106
|
+
or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"mcpServers": {
|
|
111
|
+
"openai-compatible": {
|
|
112
|
+
"command": "python",
|
|
113
|
+
"args": ["-m", "openai_compatible_mcp"],
|
|
114
|
+
"env": {
|
|
115
|
+
"DEEPSEEK_API_KEY": "sk-..."
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
See `examples/claude_desktop_config.json` for a full sample.
|
|
123
|
+
|
|
124
|
+
#### Cursor
|
|
125
|
+
|
|
126
|
+
`~/.cursor/mcp.json`:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"mcpServers": {
|
|
131
|
+
"openai-compatible": {
|
|
132
|
+
"command": "python",
|
|
133
|
+
"args": ["-m", "openai_compatible_mcp"],
|
|
134
|
+
"env": {
|
|
135
|
+
"DEEPSEEK_API_KEY": "sk-..."
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Claude Code / other stdio clients
|
|
143
|
+
|
|
144
|
+
Same shape: launch `python -m openai_compatible_mcp` as a subprocess and
|
|
145
|
+
read/write JSON-RPC over its stdin/stdout.
|
|
146
|
+
|
|
147
|
+
## Tools
|
|
148
|
+
|
|
149
|
+
### `chat`
|
|
150
|
+
|
|
151
|
+
Send a chat completion to the configured provider.
|
|
152
|
+
|
|
153
|
+
| Field | Type | Required | Description |
|
|
154
|
+
| ------------------ | --------------- | -------- | ---------------------------------------------------------- |
|
|
155
|
+
| `messages` | array | yes | List of `{role, content}` messages (oldest first). |
|
|
156
|
+
| `model` | string | no | Model name or alias (e.g. `deepseek-v4-flash`, `o1-mini`). |
|
|
157
|
+
| `temperature` | number | no | 0-2, lower = more deterministic. |
|
|
158
|
+
| `max_tokens` | integer | no | Maximum tokens to generate. |
|
|
159
|
+
| `top_p` | number | no | Nucleus sampling cutoff. |
|
|
160
|
+
| `stop` | string \| array | no | Stop sequence(s). |
|
|
161
|
+
| `system` | string | no | System prompt (prepended to the conversation). |
|
|
162
|
+
| `include_reasoning`| boolean | no | Wrap reasoning content in `<think>...</think>`. |
|
|
163
|
+
|
|
164
|
+
**Example** (from an MCP client):
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"method": "tools/call",
|
|
169
|
+
"params": {
|
|
170
|
+
"name": "chat",
|
|
171
|
+
"arguments": {
|
|
172
|
+
"messages": [
|
|
173
|
+
{"role": "user", "content": "Write a haiku about Python."}
|
|
174
|
+
],
|
|
175
|
+
"model": "deepseek-v4-flash",
|
|
176
|
+
"temperature": 0.7
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The tool returns text content with the assistant's reply plus a usage
|
|
183
|
+
footer:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
Whitespace glides through the code,
|
|
187
|
+
Indents bloom like spring leaves—
|
|
188
|
+
Bugs hide, then they are gone.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
model: deepseek-chat | prompt_tokens: 12 | completion_tokens: 28 | total_tokens: 40
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### `list_models`
|
|
195
|
+
|
|
196
|
+
Returns the default model and the alias table.
|
|
197
|
+
|
|
198
|
+
## Built-in model aliases
|
|
199
|
+
|
|
200
|
+
You can edit `src/openai_compatible_mcp/client.py` to add or remove aliases
|
|
201
|
+
for your provider. Defaults:
|
|
202
|
+
|
|
203
|
+
| Alias | Resolves to |
|
|
204
|
+
| ------------------- | -------------------- |
|
|
205
|
+
| `deepseek-v4-flash` | `deepseek-chat` |
|
|
206
|
+
| `deepseek-v4-pro` | `deepseek-chat` |
|
|
207
|
+
| `deepseek-v3` | `deepseek-chat` |
|
|
208
|
+
| `deepseek-chat` | `deepseek-chat` |
|
|
209
|
+
| `deepseek-reasoner` | `deepseek-reasoner` |
|
|
210
|
+
| `deepseek-r1` | `deepseek-reasoner` |
|
|
211
|
+
| `deepseek-coder` | `deepseek-chat` |
|
|
212
|
+
| `gpt-4o` | `gpt-4o` |
|
|
213
|
+
| `gpt-4o-mini` | `gpt-4o-mini` |
|
|
214
|
+
| `o1` | `o1` |
|
|
215
|
+
| `o1-mini` | `o1-mini` |
|
|
216
|
+
| `o3-mini` | `o3-mini` |
|
|
217
|
+
|
|
218
|
+
Any model name not in the alias table is passed through to the provider
|
|
219
|
+
unchanged, so the latest models work the moment a provider releases them.
|
|
220
|
+
|
|
221
|
+
## Smoke test
|
|
222
|
+
|
|
223
|
+
Run the server and send a few raw JSON-RPC requests over stdio:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}' | python -m openai_compatible_mcp
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Or use the included test client:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
PYTHONPATH=src python tests/smoke_test.py
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Development
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Create a venv
|
|
239
|
+
python -m venv .venv
|
|
240
|
+
.venv\Scripts\activate # Windows
|
|
241
|
+
source .venv/bin/activate # macOS / Linux
|
|
242
|
+
|
|
243
|
+
# Editable install
|
|
244
|
+
pip install -e ".[dev]"
|
|
245
|
+
|
|
246
|
+
# Run tests
|
|
247
|
+
PYTHONPATH=src python tests/smoke_test.py
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# openai-compatible-mcp
|
|
2
|
+
|
|
3
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that
|
|
4
|
+
bridges to any **OpenAI-compatible chat API** — DeepSeek, OpenAI, Azure OpenAI,
|
|
5
|
+
OpenRouter, Together, Groq, local llama.cpp, and friends.
|
|
6
|
+
|
|
7
|
+
> **Default provider:** DeepSeek. Switch to any OpenAI-compatible endpoint with
|
|
8
|
+
> a single environment variable.
|
|
9
|
+
|
|
10
|
+
The server runs over **stdio** (the standard MCP transport) and exposes two
|
|
11
|
+
tools that any MCP-compatible client can call:
|
|
12
|
+
|
|
13
|
+
- **`chat`** — send a chat completion, get the assistant's reply
|
|
14
|
+
- **`list_models`** — show the configured default model and friendly aliases
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Zero third-party dependencies (Python 3.9+ stdlib only)
|
|
19
|
+
- Works with **any** OpenAI-compatible chat API
|
|
20
|
+
- Friendly model aliases (`deepseek-v4-flash` → `deepseek-chat`, `r1` → `deepseek-reasoner`, etc.)
|
|
21
|
+
- Optional reasoning content extraction (DeepSeek-R1 style)
|
|
22
|
+
- Built-in JSON-RPC 2.0 over stdio MCP transport
|
|
23
|
+
- Tiny: ~400 lines of code
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
### 1. Install
|
|
28
|
+
|
|
29
|
+
From source:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/xiaobaotalks/openai-compatible-mcp.git
|
|
33
|
+
cd openai-compatible-mcp
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or run directly without installing:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
PYTHONPATH=src python -m openai_compatible_mcp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Configure
|
|
44
|
+
|
|
45
|
+
Set your API key and (optionally) the base URL:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# DeepSeek (default)
|
|
49
|
+
export DEEPSEEK_API_KEY="sk-..."
|
|
50
|
+
|
|
51
|
+
# OpenAI
|
|
52
|
+
export OPENAI_API_KEY="sk-..."
|
|
53
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://api.openai.com"
|
|
54
|
+
|
|
55
|
+
# Azure OpenAI
|
|
56
|
+
export OPENAI_COMPATIBLE_MCP_API_KEY="..."
|
|
57
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://YOUR-RESOURCE.openai.azure.com/openai/deployments/YOUR-DEPLOYMENT"
|
|
58
|
+
|
|
59
|
+
# Local llama.cpp server
|
|
60
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="http://127.0.0.1:8080"
|
|
61
|
+
export OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL="llama-3.1-8b"
|
|
62
|
+
|
|
63
|
+
# Custom: anything speaking the OpenAI /v1/chat/completions protocol
|
|
64
|
+
export OPENAI_COMPATIBLE_MCP_API_KEY="..."
|
|
65
|
+
export OPENAI_COMPATIBLE_MCP_BASE_URL="https://my.example.com"
|
|
66
|
+
export OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL="my-model"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Environment variable lookup order (first one set wins):
|
|
70
|
+
|
|
71
|
+
| Setting | Variables tried (in order) |
|
|
72
|
+
| ------------- | -------------------------------------------------------------------------------- |
|
|
73
|
+
| API key | `OPENAI_COMPATIBLE_MCP_API_KEY` → `DEEPSEEK_API_KEY` → `OPENAI_API_KEY` |
|
|
74
|
+
| Base URL | `OPENAI_COMPATIBLE_MCP_BASE_URL` → `DEEPSEEK_API_BASE` → `OPENAI_BASE_URL` |
|
|
75
|
+
| Default model | `OPENAI_COMPATIBLE_MCP_DEFAULT_MODEL` → `DEEPSEEK_DEFAULT_MODEL` |
|
|
76
|
+
|
|
77
|
+
### 3. Wire it up to an MCP client
|
|
78
|
+
|
|
79
|
+
#### Claude Desktop
|
|
80
|
+
|
|
81
|
+
`~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
82
|
+
or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"openai-compatible": {
|
|
88
|
+
"command": "python",
|
|
89
|
+
"args": ["-m", "openai_compatible_mcp"],
|
|
90
|
+
"env": {
|
|
91
|
+
"DEEPSEEK_API_KEY": "sk-..."
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
See `examples/claude_desktop_config.json` for a full sample.
|
|
99
|
+
|
|
100
|
+
#### Cursor
|
|
101
|
+
|
|
102
|
+
`~/.cursor/mcp.json`:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"openai-compatible": {
|
|
108
|
+
"command": "python",
|
|
109
|
+
"args": ["-m", "openai_compatible_mcp"],
|
|
110
|
+
"env": {
|
|
111
|
+
"DEEPSEEK_API_KEY": "sk-..."
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Claude Code / other stdio clients
|
|
119
|
+
|
|
120
|
+
Same shape: launch `python -m openai_compatible_mcp` as a subprocess and
|
|
121
|
+
read/write JSON-RPC over its stdin/stdout.
|
|
122
|
+
|
|
123
|
+
## Tools
|
|
124
|
+
|
|
125
|
+
### `chat`
|
|
126
|
+
|
|
127
|
+
Send a chat completion to the configured provider.
|
|
128
|
+
|
|
129
|
+
| Field | Type | Required | Description |
|
|
130
|
+
| ------------------ | --------------- | -------- | ---------------------------------------------------------- |
|
|
131
|
+
| `messages` | array | yes | List of `{role, content}` messages (oldest first). |
|
|
132
|
+
| `model` | string | no | Model name or alias (e.g. `deepseek-v4-flash`, `o1-mini`). |
|
|
133
|
+
| `temperature` | number | no | 0-2, lower = more deterministic. |
|
|
134
|
+
| `max_tokens` | integer | no | Maximum tokens to generate. |
|
|
135
|
+
| `top_p` | number | no | Nucleus sampling cutoff. |
|
|
136
|
+
| `stop` | string \| array | no | Stop sequence(s). |
|
|
137
|
+
| `system` | string | no | System prompt (prepended to the conversation). |
|
|
138
|
+
| `include_reasoning`| boolean | no | Wrap reasoning content in `<think>...</think>`. |
|
|
139
|
+
|
|
140
|
+
**Example** (from an MCP client):
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"method": "tools/call",
|
|
145
|
+
"params": {
|
|
146
|
+
"name": "chat",
|
|
147
|
+
"arguments": {
|
|
148
|
+
"messages": [
|
|
149
|
+
{"role": "user", "content": "Write a haiku about Python."}
|
|
150
|
+
],
|
|
151
|
+
"model": "deepseek-v4-flash",
|
|
152
|
+
"temperature": 0.7
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The tool returns text content with the assistant's reply plus a usage
|
|
159
|
+
footer:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
Whitespace glides through the code,
|
|
163
|
+
Indents bloom like spring leaves—
|
|
164
|
+
Bugs hide, then they are gone.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
model: deepseek-chat | prompt_tokens: 12 | completion_tokens: 28 | total_tokens: 40
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `list_models`
|
|
171
|
+
|
|
172
|
+
Returns the default model and the alias table.
|
|
173
|
+
|
|
174
|
+
## Built-in model aliases
|
|
175
|
+
|
|
176
|
+
You can edit `src/openai_compatible_mcp/client.py` to add or remove aliases
|
|
177
|
+
for your provider. Defaults:
|
|
178
|
+
|
|
179
|
+
| Alias | Resolves to |
|
|
180
|
+
| ------------------- | -------------------- |
|
|
181
|
+
| `deepseek-v4-flash` | `deepseek-chat` |
|
|
182
|
+
| `deepseek-v4-pro` | `deepseek-chat` |
|
|
183
|
+
| `deepseek-v3` | `deepseek-chat` |
|
|
184
|
+
| `deepseek-chat` | `deepseek-chat` |
|
|
185
|
+
| `deepseek-reasoner` | `deepseek-reasoner` |
|
|
186
|
+
| `deepseek-r1` | `deepseek-reasoner` |
|
|
187
|
+
| `deepseek-coder` | `deepseek-chat` |
|
|
188
|
+
| `gpt-4o` | `gpt-4o` |
|
|
189
|
+
| `gpt-4o-mini` | `gpt-4o-mini` |
|
|
190
|
+
| `o1` | `o1` |
|
|
191
|
+
| `o1-mini` | `o1-mini` |
|
|
192
|
+
| `o3-mini` | `o3-mini` |
|
|
193
|
+
|
|
194
|
+
Any model name not in the alias table is passed through to the provider
|
|
195
|
+
unchanged, so the latest models work the moment a provider releases them.
|
|
196
|
+
|
|
197
|
+
## Smoke test
|
|
198
|
+
|
|
199
|
+
Run the server and send a few raw JSON-RPC requests over stdio:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}' | python -m openai_compatible_mcp
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Or use the included test client:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
PYTHONPATH=src python tests/smoke_test.py
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Create a venv
|
|
215
|
+
python -m venv .venv
|
|
216
|
+
.venv\Scripts\activate # Windows
|
|
217
|
+
source .venv/bin/activate # macOS / Linux
|
|
218
|
+
|
|
219
|
+
# Editable install
|
|
220
|
+
pip install -e ".[dev]"
|
|
221
|
+
|
|
222
|
+
# Run tests
|
|
223
|
+
PYTHONPATH=src python tests/smoke_test.py
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "openai-compatible-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MCP server that bridges to any OpenAI-compatible chat API (DeepSeek, OpenAI, Azure, local llama.cpp, etc.)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "openai-compatible-mcp contributors" }]
|
|
13
|
+
keywords = ["mcp", "model-context-protocol", "openai", "deepseek", "llm", "chat"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
dependencies = []
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=7",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
openai-compatible-mcp = "openai_compatible_mcp.__main__:main"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
"Source" = "https://github.com/xiaobaotalks/openai-compatible-mcp"
|
|
36
|
+
"Issues" = "https://github.com/xiaobaotalks/openai-compatible-mcp/issues"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools]
|
|
39
|
+
package-dir = { "" = "src" }
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""openai-compatible-mcp: A stdio MCP server that bridges to any OpenAI-compatible chat API.
|
|
2
|
+
|
|
3
|
+
Default provider: DeepSeek. Configurable for any OpenAI-compatible endpoint.
|
|
4
|
+
Zero external dependencies - uses only the Python standard library.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|