agentic-python-coder 3.4.3__py3-none-any.whl → 3.4.4__py3-none-any.whl

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.
@@ -157,7 +157,11 @@ class PythonKernel:
157
157
  self.with_packages = with_packages or []
158
158
 
159
159
  # Set kernel's working directory
160
- kernel_kwargs = {}
160
+ # Send the kernel's fd 1 to our stderr: inherited stdout is the
161
+ # JSON-RPC pipe under ipython_mcp, and native code (e.g. solver
162
+ # progress output) writing to fd 1 would corrupt the protocol.
163
+ # print() is unaffected (ipykernel routes it over iopub).
164
+ kernel_kwargs = {"stdout": 2}
161
165
  if cwd:
162
166
  kernel_kwargs["cwd"] = cwd
163
167
 
@@ -5,6 +5,7 @@ Supports multiple concurrent kernels via kernel_id parameter.
5
5
 
6
6
  import ast
7
7
  import asyncio
8
+ import importlib.metadata
8
9
  import json
9
10
  import logging
10
11
  import os
@@ -13,7 +14,7 @@ import threading
13
14
 
14
15
  from mcp.server import Server
15
16
  from mcp.server.stdio import stdio_server
16
- from mcp.types import TextContent, Tool
17
+ from mcp.types import CallToolResult, ListToolsResult, TextContent, Tool
17
18
 
18
19
  from agentic_python_coder.kernel import (
19
20
  DEFAULT_KERNEL_ID,
@@ -27,11 +28,12 @@ from agentic_python_coder.kernel import (
27
28
  shutdown_all_kernels,
28
29
  )
29
30
 
31
+ _MCP_V2 = int(importlib.metadata.version("mcp").split(".")[0]) >= 2
32
+
30
33
  # Configure logging
31
34
  logger = logging.getLogger(__name__)
32
35
 
33
- # Create MCP server
34
- server = Server("ipython_mcp")
36
+ # The MCP server object is created at the end of the module (see _make_server).
35
37
 
36
38
  # Constants
37
39
  MAX_OUTPUT = 100 * 1024 # 100KB truncation limit
@@ -147,7 +149,6 @@ async def execute_with_timeout(
147
149
  return {"success": False, "kernel_id": kernel_id, "error": error_msg}
148
150
 
149
151
 
150
- @server.list_tools()
151
152
  async def list_tools():
152
153
  """List available MCP tools."""
153
154
  return [
@@ -296,7 +297,6 @@ Note: Call this, then call python_exec to continue working.""",
296
297
  ]
297
298
 
298
299
 
299
- @server.call_tool()
300
300
  async def call_tool(name: str, arguments: dict):
301
301
  """Handle tool calls."""
302
302
  loop = asyncio.get_running_loop()
@@ -569,6 +569,41 @@ import importlib.metadata
569
569
  ]
570
570
 
571
571
 
572
+ async def _on_list_tools(ctx, params) -> ListToolsResult:
573
+ """mcp>=2 lowlevel handler: wrap the tool list in its result type."""
574
+ return ListToolsResult(tools=await list_tools())
575
+
576
+
577
+ async def _on_call_tool(ctx, params) -> CallToolResult:
578
+ """mcp>=2 lowlevel handler.
579
+
580
+ v2 no longer wraps a returned content list, and an exception would become
581
+ a JSON-RPC error instead of an LLM-visible isError result (v1 behaviour),
582
+ so both are done here.
583
+ """
584
+ try:
585
+ content = await call_tool(params.name, params.arguments or {})
586
+ except Exception as e: # keep v1 semantics: error text reaches the model
587
+ return CallToolResult(
588
+ content=[TextContent(type="text", text=str(e))], is_error=True
589
+ )
590
+ return CallToolResult(content=content)
591
+
592
+
593
+ def _make_server() -> Server:
594
+ if _MCP_V2:
595
+ return Server(
596
+ "ipython_mcp", on_list_tools=_on_list_tools, on_call_tool=_on_call_tool
597
+ )
598
+ srv = Server("ipython_mcp")
599
+ srv.list_tools()(list_tools)
600
+ srv.call_tool()(call_tool)
601
+ return srv
602
+
603
+
604
+ server = _make_server()
605
+
606
+
572
607
  async def run_server():
573
608
  """Run the MCP server."""
574
609
  async with stdio_server() as (read, write):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: agentic-python-coder
3
- Version: 3.4.3
3
+ Version: 3.4.4
4
4
  Summary: A lightweight Python coding agent that writes, executes, and iterates on code through natural language instructions
5
5
  Author: Stefan Szeider
6
6
  License: Apache-2.0
@@ -18,7 +18,7 @@ Classifier: Topic :: Software Development :: Code Generators
18
18
  Requires-Python: >=3.13
19
19
  Requires-Dist: ipykernel>=7.3.0
20
20
  Requires-Dist: jupyter-client>=8.9.1
21
- Requires-Dist: mcp<2,>=1.28.1
21
+ Requires-Dist: mcp<3,>=1.28.1
22
22
  Requires-Dist: openai>=2.45.0
23
23
  Requires-Dist: python-dotenv>=1.2.2
24
24
  Requires-Dist: pyyaml>=6.0.3
@@ -1,9 +1,9 @@
1
1
  agentic_python_coder/__init__.py,sha256=e6o-k__u5xNIiQAkZbHtbZC2-NwpeOdi4MdQtAqJBjE,2112
2
2
  agentic_python_coder/agent.py,sha256=0JfVNO-NEss9ZNEYkYvVlJSRzIxNa6sgRqLTdsD4zbs,16484
3
3
  agentic_python_coder/cli.py,sha256=NWc1LCEL-L2TVCT6Su9a0AQ3ub3zg5GrY6XG3j_qPgI,14877
4
- agentic_python_coder/kernel.py,sha256=_gIvDvtLpYGClm5IxTAqijwHG-wi2OtKUaH2Jtk2v0Q,23511
4
+ agentic_python_coder/kernel.py,sha256=14bfNvlay7QCeUiHrOptgj-fn8ZyXfyM08lDM_lUj1M,23803
5
5
  agentic_python_coder/llm.py,sha256=ZK3b9wLzjDr6BIxUkfKhuiSDbXNR2XaQsE1J-960IzE,6998
6
- agentic_python_coder/mcp_server.py,sha256=Osdl8UnjkupXbPLiYCugiapGDJsryZfVai0o-jepuqw,22047
6
+ agentic_python_coder/mcp_server.py,sha256=aEcNWNiR8dtxQpapk72UPtEvfedIJSjRxJM1OEipcSU,23251
7
7
  agentic_python_coder/project_md.py,sha256=4xkQHlWb4cDPEkvegw1YwcfaTJ3aFbrl0CYcC_xxABY,3249
8
8
  agentic_python_coder/runner.py,sha256=Kbw1ceYJ4MVfUKgSIkiuBhMb8ZtbZuJwbBeTUsvPRts,13045
9
9
  agentic_python_coder/tools.py,sha256=tjhQbsF3n3bFIegnEOtE8czjzbtMSXy6B9gYeb-YAJ4,12088
@@ -45,8 +45,8 @@ agentic_python_coder/models/sonnet5.json,sha256=kf6DIkQlcGVZ40IzRv3GXFtNncZF_gKq
45
45
  agentic_python_coder/models/sonnet55.json,sha256=ibqrXCS21NfgE95XBeyeNrbs6XmV00eKA586uf7o0ic,97
46
46
  agentic_python_coder/prompts/system.md,sha256=hREDVAhJXwCBAgJ3AE9JD6j-JRHREUPlkRSvThOvM3A,3807
47
47
  agentic_python_coder/prompts/system_todo.md,sha256=TuNeeUNS9KqyF62Da6t2mlUCYhKsgzwGe5ic_vFPDqw,5054
48
- agentic_python_coder-3.4.3.dist-info/METADATA,sha256=Yr9xBjQt73msWBT7C5YABEO3zXSvUp3r2rUOsTdpw74,13255
49
- agentic_python_coder-3.4.3.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
50
- agentic_python_coder-3.4.3.dist-info/entry_points.txt,sha256=XIW3nZzL4kJ-Igohilj_mTvBcCyHBouDq2jmGzDILrk,107
51
- agentic_python_coder-3.4.3.dist-info/licenses/LICENSE,sha256=R9-M_V-SPdN71IphOVzM7kCNpUYs_hwj7rtroTwDhs0,11362
52
- agentic_python_coder-3.4.3.dist-info/RECORD,,
48
+ agentic_python_coder-3.4.4.dist-info/METADATA,sha256=3k071sxanjm72mzxXtF7VhzKqH4y6Rs04_284Jll994,13255
49
+ agentic_python_coder-3.4.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
50
+ agentic_python_coder-3.4.4.dist-info/entry_points.txt,sha256=XIW3nZzL4kJ-Igohilj_mTvBcCyHBouDq2jmGzDILrk,107
51
+ agentic_python_coder-3.4.4.dist-info/licenses/LICENSE,sha256=R9-M_V-SPdN71IphOVzM7kCNpUYs_hwj7rtroTwDhs0,11362
52
+ agentic_python_coder-3.4.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any