@saplings/mcp
v0.3.0
Published
AI developer tools and Model Context Protocol server for Saplings
Readme
@saplings/mcp
Local-first Model Context Protocol server for Saplings developer workflows, with bounded discovery and safe generator previews.
Run
npm install --save-dev @saplings/cli
npx sapling mcpConfigure your MCP client to execute sapling mcp over stdio (after installing the CLI version containing this feature). For a repository checkout, run pnpm run build and use node packages/cli/dist/index.js mcp. Stdout is reserved for JSON-RPC; diagnostics use stderr. By default, no file writes, shell commands, deployments, or arbitrary filesystem reads are performed.
Client configuration
For MCP clients that accept the common stdio server configuration, use:
{
"mcpServers": {
"saplings": {
"command": "node",
"args": ["/absolute/path/to/saplings/packages/cli/dist/index.js", "mcp"]
}
}
}Build the checkout first and replace the path. For clients with a different configuration schema, use the equivalent command and argument array. For VS Code, the top-level configuration key is servers rather than mcpServers. Client-specific live interoperability still needs validation. No npm publication has been performed by this PR.
Capabilities
The server uses the real Saplings catalog and a build-time snapshot of published package manifests and README guides. Tool calls provide package discovery, capability search, examples, safe application/component/API/test/CI previews, compatibility comparison and readiness evidence guidance. Resource URIs saplings://packages, saplings://package/%40saplings%2Fclient (example) and saplings://catalog expose bundled reference data. Prompts guide SaaS architecture and security review. The build also embeds allowlisted Kingsman and Harbor example configuration, Helm quality runner, Kubernetes starter deployment and quality configuration files. The billing and project-analysis tools return reference contracts and evidence requirements. Examples are documentation, not certification.
Materialize a reviewed preview
Save the generated plan JSON to a file, review every file and command, then explicitly run:
sapling mcp apply plan.json ./new-app --confirmThe CLI requires a new destination directory with a canonical existing parent, validates all paths and size limits before writing, refuses overwrites and never executes the proposed commands. MCP tool calls cannot invoke this operation. Use a trusted parent directory; if a filesystem write fails, partial output may remain for inspection and manual cleanup.
Opt-in local source scanning
Launch sapling mcp --scan-root /absolute/path/to/project to enable the real Saplings source scanner for that one host-selected project. This is stdio-only, requires a project manifest, accepts no tool-supplied paths or URLs, and returns bounded findings without source excerpts or filenames. Scan only a trusted checkout you are authorized to inspect; this is not a filesystem sandbox. Regex findings require review and do not establish security. Concurrent scan calls are rejected.
HTTP
Run sapling mcp --http with SAPLINGS_MCP_TOKEN set to a random secret of at least 32 characters and optionally SAPLINGS_MCP_PORT (default 8765). The HTTP transport is loopback-only at /mcp and requires the bearer token; no browser origins are allowed; use the exact host 127.0.0.1. Do not expose it on a public interface. OAuth, multi-tenant hosting and external gateway integration require separate work.
Official Express transport
Run sapling mcp --http-sdk with the same random local bearer credential and port settings. The official MCP server, Node and Express adapters serve the canonical tool registry. The SDK path is loopback-only and does not expose host-selected scan callbacks. The compatibility transport remains available while protocol conformance is validated.
The exact-version contract tool indexes bounded, compiled declaration files from each package. Use get_package_declaration with a listed path to follow internal re-exports. External dependency declarations are not embedded, and the contract reports whether the snapshot is incomplete. The generated Node starter has an executable smoke-test regression; README examples are still not individually certified. The AWS generator previews the checked-in OpenTofu root without provisioning.
Host-approved quality checks and extensions
Run sapling mcp --quality-bundle ./dist 1024 to enable the existing frontend gzip bundle quality engine for a trusted build directory and a 1024 KiB budget. The MCP tool accepts no path or threshold arguments, returns only status and metrics, and rejects concurrent calls. The preflight bounds file count and size; do not use a directory concurrently modified by an untrusted process.
Trusted local hosts may supply organization template previews or explicit plugin callbacks through McpOptions. Use the existing Saplings plugin registry to enforce invocation permissions and revocation inside callbacks. No dynamic loading, installation, or untrusted plugin sandbox is provided.
Gateway authorization reference
createKingsmanAuthorizer adapts Kingsman's access-token verifier with a required audience, saplings:mcp scope and explicit tenant allowlist. createAuthorizedHttpApp constructs a request-specific server from a host-selected snapshot using only the verified principal. Bind to loopback behind a reviewed Harbor/TLS deployment. To advertise a Kingsman issuer to OAuth clients, supply public HTTPS URLs:
const app = createAuthorizedHttpApp({
authorize: createKingsmanAuthorizer(identity, audience, allowedTenants),
snapshotFor: selectTenantSnapshot,
discovery: {
resourceUrl: 'https://gateway.example/mcp',
issuerUrl: 'https://identity.example/realms/developers',
},
});Route both /mcp and /.well-known/oauth-protected-resource/mcp through Harbor. The bearer challenge links to the RFC 9728 metadata document. Set the resource and issuer from trusted deployment configuration. The issuer handles authorization-server discovery and token issuance. Tenant snapshots may contain only packages visible to that tenant.
Compatibility and limits
Supports a bounded JSON-RPC implementation of the 2025-11-25 MCP handshake and 2025-06-18/2025-03-26 compatibility, with JSON-only Streamable HTTP and stdio. The official TypeScript client also exercises the shipped CLI through stdio. The default stdio and legacy HTTP paths use the compatibility implementation; the official HTTP adapter is tested with the official TypeScript client using both legacy negotiation and pinned 2026-07-28. Broader client interoperability, live gateway validation, arbitrary package type introspection, broader quality suite coverage beyond opt-in bundle checks and source scanning, full SaaS/infra generators and untrusted plugin execution remain open. Review generated code before applying it. Package versions describe the source tree at build time rather than npm's live state.
