This guide walks through installing py-code-mode and running your first agent session.
uv add git+https://github.com/xpcmdshell/py-code-mode.git@v0.15.1Global installation (available in all directories):
claude mcp add -s user py-code-mode \
-- uvx --from git+https://github.com/xpcmdshell/py-code-mode.git@v0.15.1 \
py-code-mode-mcp --base ~/.code-modeProject-scoped installation (only in the current project):
claude mcp add -s project py-code-mode \
-- uvx --from git+https://github.com/xpcmdshell/py-code-mode.git@v0.15.1 \
py-code-mode-mcp --base ./.code-modeNote: Without
-s useror-s project,claude mcp adddefaults to project scope based on your current directory. If you install from~without a scope flag, the server only works in that directory.
Verify installation:
claude mcp listThe base directory will contain workflows/, artifacts/, and optionally tools/ subdirectories.
from py_code_mode import Session
# One line setup - auto-discovers tools/, workflows/, artifacts/, requirements.txt
async with Session.from_base("./data") as session:
result = await session.run('''
# Search for existing workflows
results = workflows.search("data processing")
# List available tools
all_tools = tools.list()
# Create a simple workflow
workflows.create(
name="hello_world",
source="""async def run(name: str = "World") -> str:
return f"Hello, {name}!"
""",
description="Simple greeting function"
)
# Invoke the workflow
greeting = workflows.invoke("hello_world", name="Python")
print(greeting)
''')
print(f"Result: {result.value}")Need process isolation?
async with Session.subprocess("~/.code-mode") as session:
...Once installed, the MCP server provides these tools to Claude:
run_code- Execute Python code withtools,workflows,artifacts,depsnamespaceslist_tools,search_tools- Discover available toolslist_workflows,search_workflows,create_workflow,delete_workflow- Manage workflowslist_artifacts- View stored datalist_deps,add_dep,remove_dep- Manage dependencies
Just ask Claude to use py-code-mode:
Can you search for workflows related to GitHub analysis?
Claude will use the search_workflows MCP tool automatically.
- Search for existing workflows - Always check if someone already solved this
- Invoke if found - Reuse existing workflows
- Script if not found - Write code to solve the problem
- Create workflow if reusable - Save successful workflows for future use
# 1. Search
results = workflows.search("fetch json from url")
# 2. Invoke if found
if results:
data = workflows.invoke(results[0]["name"], url="https://api.example.com/data")
else:
# 3. Script the solution
import json
response = tools.curl.get(url="https://api.example.com/data")
data = json.loads(response)
# 4. Save as workflow
workflows.create(
name="fetch_json",
source='''async def run(url: str) -> dict:
import json
response = tools.curl.get(url=url)
return json.loads(response)
''',
description="Fetch and parse JSON from a URL"
)