Skip to content

feat(mcp): add MCP server with in-process command execution#98

Merged
pcfreak30 merged 1 commit into
developfrom
feat/mcp-server
Jul 4, 2026
Merged

feat(mcp): add MCP server with in-process command execution#98
pcfreak30 merged 1 commit into
developfrom
feat/mcp-server

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

  • MCP adapter exposes CLI subcommands as MCP tools via in-process execution (root.Run with buffer capture, no subprocess fork)
  • FSM-based wizard sessions for website onboarding and setup flows
  • Step input types with JSON schemas for structured wizard navigation
  • MCP resources: account status, website DNS/validation, session state
  • MCP prompt templates for website-onboarding and setup workflows
  • Factory pattern: pkg/cli provides concrete wizard implementations
  • Output formatter propagates root writer for in-process MCP capture

Description

This PR adds a Model Context Protocol (MCP) server to pinner-cli, enabling AI agents to discover and invoke CLI commands as MCP tools, access live data via pinner:// resources, and drive interactive wizard workflows through structured prompts.

Key additions:

MCP Server & Tool Adapter (pkg/internal/mcp/adapter.go): Exposes all non-hidden CLI subcommands as MCP tools over stdio. Tool invocations execute the command tree in-process (no subprocess fork), capturing stdout/stderr into buffers and returning results to the agent. Extended flag-type support beyond the upstream adapter to include Float, Duration, and StringSlice flags.

MCP Resources (pkg/internal/mcp/resources.go): Registers four pinner:// resources that agents can read at runtime:

  • pinner://account/status — auth state, quota, and masked config summary
  • pinner://websites/{domain}/dns-requirements — DNS records the user must configure
  • pinner://websites/{id}/validation-status — live website validation result
  • pinner://wizard/{session_id}/state — current wizard FSM state and next-step schema

MCP Prompts (pkg/internal/mcp/prompts.go): Two prompt templates that generate step-by-step instructions for agents:

  • website-onboarding — guides the agent through the website creation wizard (auth check, content source, target type, domain, DNS mode, create, DNS setup, validate)
  • setup — guides the agent through initial setup (auth, config, shell completion, tutorial)

Wizard Session Engine (pkg/internal/mcp/session.go, wizard.go): A TTL-bounded, in-memory session store with FSM-driven step progression. Each step validates JSON input, mutates wizard state, and returns a StepResponse containing the next step name and its expected input schema. Sessions support retry on handler errors (FSM stays in the same state) and abort transitions from any step. Two wizard types are implemented: websites creation and initial setup.

CLI Integration: The mcp subcommand is wired into the root command. Output formatters now respect the root command's writer, allowing in-process execution to capture output into buffers when invoked by the MCP adapter.

@kody-ai

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code Coverage Report

Total Coverage: 54.4%

Generated from commit: 737d426
Repository: LumeWeb/pinner-cli

Comment thread pkg/cli/root.go
Comment thread pkg/internal/mcp/adapter.go Outdated
Comment thread pkg/internal/mcp/session.go Outdated
@kody-ai

This comment has been minimized.

@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go Outdated
Comment thread pkg/internal/mcp/adapter.go Outdated
Comment thread pkg/internal/mcp/session.go
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go Outdated
Comment thread pkg/internal/mcp/adapter.go Outdated
Comment thread pkg/internal/mcp/resources.go
Comment thread pkg/internal/mcp/wizard.go Outdated
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go Outdated
Comment thread pkg/internal/mcp/adapter.go Outdated
Comment thread pkg/internal/mcp/wizard.go Outdated
Comment thread pkg/internal/mcp/wizard.go Outdated
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/mcp_adapters.go Outdated
Comment thread pkg/internal/mcp/adapter.go Outdated
Comment thread pkg/internal/mcp/session.go
Comment thread pkg/internal/mcp/wizard.go
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go Outdated
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/mcp_adapters.go
Comment thread pkg/internal/mcp/adapter.go Outdated

@kody-ai kody-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go
Comment thread pkg/internal/mcp/adapter.go Outdated
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/root.go
Comment thread pkg/internal/mcp/adapter.go
@kody-ai

This comment has been minimized.

Comment thread pkg/cli/mcp_adapters.go
Comment thread pkg/cli/root.go Outdated
Comment thread pkg/internal/mcp/resources.go Outdated
@kody-ai

This comment has been minimized.

Comment thread pkg/internal/mcp/adapter.go
- Add MCP server with in-process command execution via root.Run
- Wire RegisterWizardTools using WizardDepsFactory called at Action
  time, not construction time
- Parameterless factory closures (func() State) — wizard constructors
  capture their own deps
- Remove ConfigManager()/AuthService() from wizard state interfaces;
  step handlers access services via deps
- Add max sessions enforcement to SessionStore (DefaultMaxSessions=100)
  with automatic expired-session eviction on Create
- NewSessionStoreWithLimits constructor for custom TTL + max
- Restore root.Writer/ErrWriter with defer in MCP command execution
- Add tests for max sessions, eviction, and all wizard tool flows
@kody-ai

kody-ai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@pcfreak30 pcfreak30 marked this pull request as ready for review July 4, 2026 04:39
@pcfreak30 pcfreak30 merged commit 7db529c into develop Jul 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants