codex-as-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.
- codex_as_mcp-0.1.0/PKG-INFO +22 -0
- codex_as_mcp-0.1.0/README.md +3 -0
- codex_as_mcp-0.1.0/pyproject.toml +29 -0
- codex_as_mcp-0.1.0/setup.cfg +4 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp/__main__.py +6 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp/server.py +89 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/PKG-INFO +22 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/SOURCES.txt +10 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/dependency_links.txt +1 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/entry_points.txt +2 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/requires.txt +1 -0
- codex_as_mcp-0.1.0/src/codex_as_mcp.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codex-as-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server that provides access to codex CLI for code generation and review
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/yourusername/codex-as-mcp
|
|
7
|
+
Project-URL: Repository, https://github.com/yourusername/codex-as-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/yourusername/codex-as-mcp/issues
|
|
9
|
+
Keywords: mcp,codex,code-generation,ai
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: mcp[cli]>=1.12.4
|
|
19
|
+
|
|
20
|
+
# codex-as-mcp
|
|
21
|
+
|
|
22
|
+
Convert codex CLI tool to an MCP — unleash the power of GPT-5
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "codex-as-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "MCP server that provides access to codex CLI for code generation and review"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Your Name", email = "your.email@example.com"}
|
|
9
|
+
]
|
|
10
|
+
keywords = ["mcp", "codex", "code-generation", "ai"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"mcp[cli]>=1.12.4",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
codex-as-mcp = "codex_as_mcp.server:main"
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/yourusername/codex-as-mcp"
|
|
28
|
+
Repository = "https://github.com/yourusername/codex-as-mcp"
|
|
29
|
+
Issues = "https://github.com/yourusername/codex-as-mcp/issues"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP, Context
|
|
2
|
+
import subprocess
|
|
3
|
+
import re
|
|
4
|
+
from typing import List, Dict, Optional, Sequence
|
|
5
|
+
|
|
6
|
+
mcp = FastMCP("codex-as-mcp")
|
|
7
|
+
|
|
8
|
+
HEADER_RE = re.compile(
|
|
9
|
+
r'^'
|
|
10
|
+
r'\[(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\]' # 1: timestamp
|
|
11
|
+
r'\s+'
|
|
12
|
+
r'([^\n]+)' # 2: tag (整行,允许包含空格/冒号)
|
|
13
|
+
r'\n',
|
|
14
|
+
flags=re.M
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
BLOCK_RE = re.compile(
|
|
18
|
+
r'^'
|
|
19
|
+
r'\[(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\]\s+([^\n]+)\n' # 1: ts, 2: tag
|
|
20
|
+
r'(.*?)' # 3: body
|
|
21
|
+
r'(?=^\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\]\s+[^\n]+\n|\Z)',
|
|
22
|
+
flags=re.M | re.S
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def run_and_extract_codex_blocks(
|
|
26
|
+
cmd: Sequence[str],
|
|
27
|
+
tags: Optional[Sequence[str]] = ("codex",),
|
|
28
|
+
last_n: int = 1
|
|
29
|
+
) -> List[Dict[str, str]]:
|
|
30
|
+
"""
|
|
31
|
+
运行命令并抽取日志块。每个块由形如
|
|
32
|
+
[YYYY-MM-DDTHH:MM:SS] <tag>
|
|
33
|
+
<正文...直到下一个时间戳头或文件结束>
|
|
34
|
+
组成。
|
|
35
|
+
|
|
36
|
+
:param cmd: 完整命令(列表形式)
|
|
37
|
+
:param tags: 需要过滤的 tag 列表(大小写不敏感)。None 表示不过滤。
|
|
38
|
+
:param last_n: 返回最后 N 个匹配块
|
|
39
|
+
:return: [{timestamp, tag, body, raw}] 按时间顺序(旧->新)
|
|
40
|
+
"""
|
|
41
|
+
proc = subprocess.run(
|
|
42
|
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
|
|
43
|
+
)
|
|
44
|
+
out = proc.stdout
|
|
45
|
+
|
|
46
|
+
blocks = []
|
|
47
|
+
for m in BLOCK_RE.finditer(out):
|
|
48
|
+
ts, tag, body = m.group(1), m.group(2).strip(), m.group(3)
|
|
49
|
+
if tags is None or tag.lower() in {t.lower() for t in tags}:
|
|
50
|
+
raw = f'[{ts}] {tag}\n{body}'
|
|
51
|
+
blocks.append({"timestamp": ts, "tag": tag, "body": body, "raw": raw})
|
|
52
|
+
|
|
53
|
+
# 只取最后 1 个
|
|
54
|
+
return blocks[-last_n:]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@mcp.tool()
|
|
58
|
+
async def codex_execute(prompt: str, work_dir: str, ctx: Context) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Execute prompt using codex for general purpose.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
prompt (str): The prompt for codex
|
|
64
|
+
work_dir (str): The working directory, e.g. /Users/kevin/Projects/demo_project
|
|
65
|
+
ctx (Context): MCP context for logging
|
|
66
|
+
"""
|
|
67
|
+
cmd = [
|
|
68
|
+
"codex", "exec",
|
|
69
|
+
"--full-auto", "--skip-git-repo-check",
|
|
70
|
+
"--cd", work_dir,
|
|
71
|
+
prompt,
|
|
72
|
+
]
|
|
73
|
+
return run_and_extract_codex_blocks(cmd)[-1]["raw"]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main():
|
|
77
|
+
"""Entry point for the MCP server"""
|
|
78
|
+
import asyncio
|
|
79
|
+
from mcp.server.stdio import stdio_server
|
|
80
|
+
|
|
81
|
+
async def run():
|
|
82
|
+
async with stdio_server() as (read_stream, write_stream):
|
|
83
|
+
await mcp.run(read_stream, write_stream, mcp.create_initialization_options())
|
|
84
|
+
|
|
85
|
+
asyncio.run(run())
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
main()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codex-as-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server that provides access to codex CLI for code generation and review
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/yourusername/codex-as-mcp
|
|
7
|
+
Project-URL: Repository, https://github.com/yourusername/codex-as-mcp
|
|
8
|
+
Project-URL: Issues, https://github.com/yourusername/codex-as-mcp/issues
|
|
9
|
+
Keywords: mcp,codex,code-generation,ai
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: mcp[cli]>=1.12.4
|
|
19
|
+
|
|
20
|
+
# codex-as-mcp
|
|
21
|
+
|
|
22
|
+
Convert codex CLI tool to an MCP — unleash the power of GPT-5
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/codex_as_mcp/__main__.py
|
|
4
|
+
src/codex_as_mcp/server.py
|
|
5
|
+
src/codex_as_mcp.egg-info/PKG-INFO
|
|
6
|
+
src/codex_as_mcp.egg-info/SOURCES.txt
|
|
7
|
+
src/codex_as_mcp.egg-info/dependency_links.txt
|
|
8
|
+
src/codex_as_mcp.egg-info/entry_points.txt
|
|
9
|
+
src/codex_as_mcp.egg-info/requires.txt
|
|
10
|
+
src/codex_as_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcp[cli]>=1.12.4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
codex_as_mcp
|