{"id":35094119,"url":"https://github.com/portofcontext/pctx","last_synced_at":"2026-04-02T15:46:26.350Z","repository":{"id":323557353,"uuid":"1089674529","full_name":"portofcontext/pctx","owner":"portofcontext","description":"pctx is the execution layer for agentic tool calls. It exposes custom tools and MCP servers as code that runs in secure sandboxes for token-efficient calls.","archived":false,"fork":false,"pushed_at":"2026-02-12T21:09:19.000Z","size":23351,"stargazers_count":200,"open_issues_count":2,"forks_count":21,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-13T00:37:27.361Z","etag":null,"topics":["ai-agents","api","infrastructure","local-development","mcp","mcp-server","open-source"],"latest_commit_sha":null,"homepage":"https://portofcontext.com","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/portofcontext.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-04T16:54:23.000Z","updated_at":"2026-02-12T15:52:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/portofcontext/pctx","commit_stats":null,"previous_names":["portofcontext/pctx"],"tags_count":48,"template":false,"template_full_name":null,"purl":"pkg:github/portofcontext/pctx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portofcontext%2Fpctx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portofcontext%2Fpctx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portofcontext%2Fpctx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portofcontext%2Fpctx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/portofcontext","download_url":"https://codeload.github.com/portofcontext/pctx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portofcontext%2Fpctx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29452749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","api","infrastructure","local-development","mcp","mcp-server","open-source"],"created_at":"2025-12-27T15:04:24.312Z","updated_at":"2026-04-02T15:46:26.337Z","avatar_url":"https://github.com/portofcontext.png","language":"Rust","funding_links":[],"categories":["Rust","📚 Projects (1974 total)","Self-hosted / Open Source"],"sub_categories":["MCP Servers"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\".github/assets/logo.png\" alt=\"PCTX Logo\" style=\"height: 128px\"\u003e\n  \u003ch1\u003epctx\u003c/h1\u003e\n\n[![Made by](https://img.shields.io/badge/MADE%20BY-Port%20of%20Context-1e40af.svg?style=for-the-badge\u0026labelColor=0c4a6e)](https://portofcontext.com)\n\n[![NPM Version](https://img.shields.io/npm/v/%40portofcontext%2Fpctx)](https://www.npmjs.com/package/@portofcontext/pctx)\n[![Rust](https://img.shields.io/badge/rust-1.89%2B-green.svg)](https://www.rust-lang.org)\n[![Python](https://img.shields.io/pypi/v/pctx-client?color=blue)](https://pctx.readthedocs.io/en/latest/)\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\nThe open source framework to connect AI agents to tools and mcp with [Code Mode](#what-is-code-mode)\n\n\u003c/div\u003e\n\n## Install\n\n```bash\n# Homebrew\nbrew install portofcontext/tap/pctx\n\n# cURL\ncurl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/portofcontext/pctx/main/install.sh | sh\n\n# npm\nnpm i -g @portofcontext/pctx\n```\n\n## Core Functionality\n\npctx can be run as a stateless HTTP server for Code Mode sessions or as a unified MCP server that exposes Code Mode functionality for registered upstream MCP servers.\n\n```bash\n# Start Code Mode for Python SDK\npctx start\n\n# Start Code Mode as a unified MCP server\npctx mcp init\npctx mcp dev\n```\n\n## Python SDK\n\nUse the Python SDK if building agents in Python and want to run Code Mode with custom tools and/or MCP servers. The Python SDK is an HTTP client to the `pctx` server.\n\n```bash\npip install pctx-client\n```\n\n```python\nfrom pctx_client import Pctx, tool\nfrom agents import Agent # Use any Agent SDK\nfrom agents.run import Runner # This example is OpenAI Agents SDK\n\n@tool\ndef get_weather(city: str) -\u003e str:\n    \"\"\"Get weather information for a given city.\"\"\"\n    return f\"It's always sunny in {city}!\"\n\npctx = Pctx(tools=[get_weather]) # or with mcp: servers=[your_mcp]\n\ntools = pctx.openai_agents_tools() # Run Code Mode with any Agent SDK\nagent = Agent(\n    name=\"GreatCoder\",\n    model=\"litellm/openrouter/openai/gpt-oss-120b\",\n    instructions=\"You run code to complete complex tasks.\",\n    tools=tools,\n)\n```\n\n### Links\n\n- [Python SDK Quickstart and Docs](./pctx-py/README.md)\n- [Python API Reference](https://pctx.readthedocs.io/en/latest/)\n\n## Node SDK\n\nComing soon\n\n## Unified MCP\n\nUse the unified MCP to run Code Mode with MCP servers and want to persist the authentication connections and you do not need to use agent tools (non-mcp tools).\n\n```bash\n# Initialize config for upstream mcp connections\npctx mcp init\n\n# Add HTTP or stdio MCP servers\npctx mcp add stripe https://mcp.stripe.com\npctx mcp add memory --command \"npx -y @modelcontextprotocol/server-memory\"\n\n# Start as HTTP server (dev mode with UI)\npctx mcp dev\n\n# Or start as stdio MCP server\npctx mcp start --stdio\n```\n\nFor complete CLI documentation, see [CLI.md](docs/CLI.md).\nFor configuration options, see [Configuration Guide](docs/config.md).\n\n\u003cimg width=\"1020\" height=\"757\" alt=\"Screenshot 2025-11-21 at 11 03 20 AM\" src=\"https://github.com/user-attachments/assets/d61be46d-5a4b-40fd-953a-7dc725266e63\" /\u003e\n\n## What is pctx?\n\n`pctx` sits between AI agents and MCP servers. It aggregates multiple upstream MCP servers, handles authentication, and exposes tools through a unified [Code Mode](#what-is-code-mode) interface. Instead of agents managing connections to individual MCP servers, they connect once to pctx.\n\n## What is Code Mode?\n\nCode mode replaces sequential tool calling with code execution. Rather than an agent calling tools one at a time and passing results through its context window, it writes code that executes in a sandbox. Read Anthropic's overview [here](https://www.anthropic.com/engineering/code-execution-with-mcp).\n\n**Traditional MCP flow**:\n\n1. Agent calls `getSheet(id)`\n2. Server returns 1000 rows → agent's context\n3. Agent calls `filterRows(criteria)`\n4. Server returns 50 rows → agent's context\n\n**With Code Mode**:\n\n```typescript\nconst sheet = await gdrive.getSheet({ sheetId: \"abc\" });\nconst orders = sheet.filter((row) =\u003e row.status === \"pending\");\nconsole.log(`Found ${orders.length} orders`);\n```\n\n**Result:** 98.7% reduction in tokens (150k → 2k) for this multi-step operation.\n\n## Features\n\n- **Code Mode interface**: Tools exposed as code functions for efficient agent interaction. See [Code Mode Guide](docs/code-mode.md).\n- **Upstream MCP server aggregation**: Connect to multiple MCP servers through a single interface, with persistent upstream sessions across `execute_typescript` calls. See [Upstream MCP Servers Guide](docs/upstream-mcp-servers.md).\n- **Simple config with CLI**: Create the pctx.json config with a simple CLI. pctx.json manages auth, upstream MCPs, logging, and more. See [Config Guide](docs/config.md).\n- **Secure authentication**: Source secrets from environment variables, system keychain, and external commands. See [Authentication Section](docs/config.md#authentication) in the CLI configuration docs for more details.\n\n## Security\n\n- LLM generated code runs in an isolated [Deno](https://deno.com) sandbox that can only access the network hosts specified in the configuration file.\n- No filesystem, environment, network (beyond allowed hosts), or system access.\n- MCP clients are authenticated in pctx. LLMs can never see your auth.\n\n## Update\n\nDepending on the installation method (Homebrew/npm/cURL) the update method is different. Run `which pctx` if you are unsure what you used to install it.\n\n```bash\n# Homebrew update\nbrew upgrade pctx\n\n# cURL update\npctx-update\n\n# npm update\nnpm upgrade -g @portofcontext/pctx\n\n```\n\n## Develop\n\n- For core dev: install rust and jump into `crates/`\n- Client SDK dev: find the README in the SDK\n\n## Learn More\n\n- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)\n- [Code execution with MCP by Anthropic](https://www.anthropic.com/engineering/code-execution-with-mcp)\n- [Code Mode explanation by Cloudflare](https://blog.cloudflare.com/code-mode/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fportofcontext%2Fpctx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fportofcontext%2Fpctx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fportofcontext%2Fpctx/lists"}