● Сообщество
portofcontext
⚡ Сразу
pctx
автор portofcontext · portofcontext/pctx
Run MCP tool calls as sandboxed JavaScript — one code block replaces many sequential calls, saving tokens and isolating credentials.
pctx (Port of Context) is an execution layer that converts MCP servers into JS functions callable from inside Deno sandboxes. The LLM writes code that composes many tool calls at once; pctx runs it with no filesystem/env access and network allowlisting. Credentials stay at the pctx layer — the LLM never sees them.
Зачем использовать
Ключевые функции
- Code Mode: one LLM code block can chain many MCP tool calls in one turn
- Deno sandbox: no FS, no env, allowlisted network only
- Aggregates multiple upstream MCP servers behind one pctx
- Credential-proofing: LLM never sees keys — pctx injects them
- Install via Homebrew, npm -g, or curl-pipe script
Живое демо
Как выглядит на практике
Сценарии использования
Реальные сценарии: pctx
Когда использовать: A task needs many tool calls (fetch N issues, enrich each, post summary).
Предварительные требования
- pctx installed and configured — brew install portofcontext/tap/pctx; pctx config add <upstream-mcp>
Поток
-
Register upstreams with credentials
pctx config add github --env GITHUB_TOKEN=... and add sentry --env SENTRY_TOKEN=....✓ Скопировано
→ Upstreams listed
-
Ask agent to write Code Mode
In pctx Code Mode, write a function that fetches the 10 newest Sentry issues, for each finds the releasing commit via github, and returns a summary array.✓ Скопировано
→ Code block + single execution result
-
Inspect the result
Summarize the array in English and flag any issue whose releasing commit was by a specific author.✓ Скопировано
→ Final answer grounded in the data
Итог: 10x fewer tool-call round-trips, major token savings, same result.
Подводные камни
- Sandboxed code errors are opaque if you don't surface stderr — Wrap the code in try/catch and print caught errors so the LLM can self-correct
- Network allowlist too tight — legitimate calls blocked — Start broad, narrow based on actual host usage from logs
Когда использовать: Your threat model says 'LLM must never see the token in any form'.
Поток
-
Store creds in pctx
Add a keychain-backed credential to pctx for github.✓ Скопировано
→ Credential stored, not visible to callers
-
Verify from the other side
Ask the LLM to 'print the GitHub token' — confirm it cannot.✓ Скопировано
→ LLM has no way to access the secret
Итог: A reproducible answer to 'can the LLM exfiltrate our tokens?' — no.
Когда использовать: You want Code Mode semantics across github, postgres, filesystem in one place.
Поток
-
Register each
Add github, postgres (read-only), and filesystem (scoped to /data) to pctx.✓ Скопировано
→ All three callable from code
-
Write a cross-MCP job
Write pctx code that reads a SQL query result and writes CSV to /data/out.csv, then creates a GitHub gist with that CSV.✓ Скопировано
→ Single execution, three upstreams used
Итог: A unified, sandboxed execution plane for mixed-upstream workflows.
Комбинации
Сочетайте с другими MCP — эффект x10
Cross-reference Sentry issues with GitHub commits in one sandboxed code block
Via pctx Code Mode: for every new Sentry issue, find the GitHub commit that introduced it and return a table.✓ Скопировано
Query + transform + export in one sandbox
pctx code that runs a Postgres read, pivots the result in JS, and writes /data/report.json.✓ Скопировано
Стоимость и лимиты
Во что обходится
- Квота API
- No pctx quota; upstream calls inside code incur their own
- Токенов на вызов
- Code Mode is far cheaper token-wise than many sequential tool calls
- Деньги
- Free, open source
- Совет
- For tasks over 5 tool calls, Code Mode typically saves 50%+ tokens vs sequential calling.
Безопасность
Права, секреты, радиус поражения
Хранение учётных данных: Env vars, OS keychain, or external command — LLM never sees credentials
Исходящий трафик: Only to hosts explicitly allowlisted per upstream
Никогда не давайте: Allowlist the open internet in the sandbox — pin to specific hosts
- Review what upstream tools the LLM-generated code calls — sandbox is network-scoped, not semantic.
- Deno sandbox is strong but not infinite — treat it as defense in depth, not the only control.
Устранение неполадок
Частые ошибки и исправления
Network denied in sandbox
Add the host to the upstream's allowlist in pctx config.
Проверить: pctx config show
Credential not injected
Credential name mismatch; pctx logs the resolved key on startup.
Проверить: pctx run --debug
Code Mode returns a vague 'sandbox violation'
Enable verbose logs; most violations are env or FS access attempts the LLM shouldn't make.
Проверить: pctx logs --tail
Альтернативы
pctx в сравнении
| Альтернатива | Когда использовать | Компромисс |
| proxy-2 / 1mcp-agent | You want aggregation but not Code Mode / sandboxing | LLM calls each tool separately; can see whatever the MCP returns |
| Bare execution via shell MCP | You want code execution but don't need MCP proxying | No credential isolation, no allowlist |