SPEC: MCP Mode Skill Generation
Replaces MCP mode's raw document dump with an LLM-generated SKILL.md file containing actionable instructions and code patterns.
What this file does
Replaces MCP mode's raw document dump with an LLM-generated SKILL.md file containing actionable instructions and code patterns.
When to use it
- You want MCP mode to return structured LLM instructions instead of raw docs
- You are building a RAG pipeline that synthesises retrieved docs into a skill format
- You need to add DSPy-based skill generation to an existing MCP endpoint
- You are updating tests for a new skill generation module
Assumes this stack
SPEC: MCP Mode Skill Generation
Summary
Replace MCP mode's raw document dump with an LLM-powered step that synthesizes retrieved docs into a Claude Code skill file (SKILL.md format). Instead of returning unstructured documentation, MCP mode will return precise, actionable LLM instructions that callers can use directly.
Background
- MCP mode is triggered by the
x-mcp-modeormcpHTTP header - Currently it skips LLM generation and returns raw docs formatted as markdown (title, source, URL, content)
- This is suboptimal: modern models work better with precise instructions in the skill format than with raw context dumps
- The skill format has YAML frontmatter (
name,description) and a markdown body with instructions, examples, and code patterns
Requirements
1. New DSPy Signature: SkillGeneration
File: python/src/cairo_coder/dspy/generation_program.py
Create a new DSPy Signature that takes a query and retrieved documents and produces a SKILL.md string.
Inputs:
query(str): The original user querycontext(str): Retrieved documents formatted as context (reuse_prepare_context()from the pipeline)
Output:
skill(str): A complete SKILL.md file content
The output must follow this structure:
---
name: <kebab-case-name-derived-from-query>
description: <1-2 sentence description of what this skill does and when to use it>
---
<Markdown body with:>
- Clear instructions for the LLM
- Relevant code examples extracted from the retrieved docs
- Cairo/Starknet-specific patterns and best practices
- Source references where applicable
2. New DSPy Module: SkillGenerationProgram
File: python/src/cairo_coder/dspy/generation_program.py
Replace McpGenerationProgram with SkillGenerationProgram:
- Wraps the
SkillGenerationsignature in adspy.ChainOfThoughtmodule - Implements both
forward()andaforward()(async) - Uses the same LLM as the normal generation path
Update the factory function create_mcp_generation_program() to return a SkillGenerationProgram instance.
3. Update RAG Pipeline MCP Branch
File: python/src/cairo_coder/core/rag_pipeline.py
In both aforward() (line ~181) and aforward_streaming() (line ~260):
- The MCP branch currently calls
self.mcp_generation_program.acall(documents) - Change it to prepare context first (call
self._prepare_context(documents)) and then callself.mcp_generation_program.acall(query=query, context=context) - The response field changes from
result.answertoresult.skill
4. Update Tests
Unit tests in python/tests/unit/test_generation_program.py:
- Test
SkillGenerationProgramproduces valid SKILL.md output - Test output contains YAML frontmatter with
nameanddescription - Test output contains markdown body
- Test empty documents case
Unit tests in python/tests/unit/test_rag_pipeline.py:
- Update existing MCP mode tests to expect skill format instead of raw docs
5. Remove Dead Code
- Delete
McpGenerationProgramclass - Delete old
create_mcp_generation_program()factory (replace with new one)
Out of Scope
- Saving generated skills to disk
- New HTTP headers or endpoints (still uses
x-mcp-mode) - Changes to the ingester or document retrieval pipeline
- Optimizing the skill generation prompt with DSPy optimizers (future work)
Acceptance Criteria
x-mcp-moderequests return a valid SKILL.md string instead of raw docs- Output contains YAML frontmatter with
nameanddescriptionfields - Output contains actionable instructions (not just pasted docs)
- All existing tests pass (updated for new format)
- New unit tests for
SkillGenerationProgram uv run pytestpasses frompython/directorytrunk check --fixpasses from repo root
Verification Commands
cd python && uv run pytest -v
trunk check --fix
What's inside
5 requirement sections, 1 out-of-scope list, 7 acceptance criteria, 2 verification commands
Change this for your project
- Replace
python/src/cairo_coder/dspy/generation_program.pywith your own module path - Replace
python/src/cairo_coder/core/rag_pipeline.pywith your own pipeline file - Replace
python/tests/unit/test_generation_program.pywith your test file path - Replace
python/tests/unit/test_rag_pipeline.pywith your test file path
Where it goes
Keep in docs/ or alongside the feature. Agents read it to implement against a defined contract.
Worth borrowing
- Using DSPy ChainOfThought to wrap a signature that outputs structured markdown with YAML frontmatter
- Preparing context from retrieved documents before passing to the generation program
Related Documents
GPU Selection Guide for Large Language Models (LLMs)
Guides GPU selection for LLM inference, fine-tuning, and training by mapping model sizes, precision levels, and budgets to VRAM requirements.
Community AI Agent Skills Discovery Sources
Catalogs 50+ platforms, repositories, directories, and communities for discovering and sharing AI agent skills across multiple coding tools.
ReleaseKit - Technical Requirements Document
Specifies a Go library and CLI for release automation with conventional commit parsing, validation checks, and workflow orchestration.
api_llm Specification
Defines a workspace of thin HTTP API clients for major LLM providers with no abstraction layer and explicit developer control.