Skip to content
 
 

Repository files navigation

PCTX Logo

pctx

Made by

NPM Version Rust CI

The open source framework to connect AI agents to tools and services with code mode

Install

# Homebrew
brew install portofcontext/tap/pctx

# Curl
curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/portofcontext/pctx/main/install.sh | sh

# NPM
npm i -g @portofcontext/pctx

Quick Start

# Initialize config for upstream mcp connections
pctx init

# Connect to any MCP server
pctx add my-local-server http://localhost:3000/mcp
pctx add stripe https://mcp.stripe.com

# Start the unified MCP server
pctx start

For complete CLI documentation, see CLI.md. For configuration options, see Configuration Guide.

What is pctx?

pctx sits between AI agents and MCP servers. It aggregates multiple upstream MCP servers, handles authentication, and exposes tools through a unified Code Mode interface. Instead of agents managing connections to individual MCP servers, they connect once to pctx.

What is Code Mode?

Code 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 TypeScript code that executes in a sandbox. Read Anthropic's overview here.

Traditional MCP flow:

  1. Agent calls getSheet(id)
  2. Server returns 1000 rows → agent's context
  3. Agent calls filterRows(criteria)
  4. Server returns 50 rows → agent's context

With Code Mode:

const sheet = await gdrive.getSheet({ sheetId: "abc" });
const orders = sheet.filter((row) => row.status === "pending");
console.log(`Found ${orders.length} orders`);

Result: 98.7% reduction in tokens (150k → 2k) for this multi-step operation.

Features

  • Code Mode interface: Tools exposed as TypeScript functions for efficient agent interaction. See Code Mode Guide.
  • Upstream MCP server aggregation: Connect to multiple MCP servers through a single interface. See Upstream MCP Servers Guide.
  • Secure authentication: OAuth, environment variables, system keychain, and external commands. See Authentication Guide.

Architecture

    Runs locally • in docker • any cloud

  ┌─────────────────────────────────┐
  │      AI Agents (Bring any LLM)  │
  └──────────────-──────────────────┘
                │ MCP
                │ • list_functions
                │ • get_function_details
                │ • execute
  ┌─────────────▼───────────────────┐
  │            pctx                 │
  │                                 │
  │  ┌─────────────────────────┐    │
  │  │  TypeScript Compiler    │    │
  │  │  Sandbox (Deno)         │    │
  │  │                         │    │
  │  │  • Type checking        │    │
  │  │  • Rich error feedback  │    │
  │  │  • No network access    │    │
  │  └──────────┬──────────────┘    │
  │             │ Compiled JS       │
  │  ┌──────────▼──────────────┐    │
  │  │  Execution Sandbox      │    │
  │  │  (Deno Runtime)         │    │
  │  │                         │    │
  │  │  • Authenticated MCP    │    │
  │  │    client connections   │    │
  │  │  • Restricted network   │    │
  │  │  • Tool call execution  │    │
  │  └──┬──────┬──────┬────────┘    │
  └─────┼──────┼──────┼─────────────┘
        │      │      │
        ↓      ↓      ↓
    ┌──────┬──────┬──────┬──────┐
    │Local │Slack │GitHub│Custom│
    └──────┴──────┴──────┴──────┘

Security

  • LLM generated code runs in an isolated Deno sandbox that can only access the network hosts specified in the configuration file.
  • No filesystem, environment, network (beyond allowed hosts), or system access.
  • MCP clients are authenticated in pctx. LLMs can never see your auth.

Learn More

About

The pctx framework replaces LLM tool calling with a Code Mode that runs in secure sandboxes.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages