Skip to content

Commit eab3bf7

Browse files
feat: Phase 3 MCP agent integration — FastMCP server with 6 tools
MCP server for AI coding assistant integration (Claude Code, Gemini CLI, Kiro): - mcp/server.py: FastMCP v1 with lifespan pattern (shared DB + settings) stdio transport, register via `claude mcp add studyctl-mcp` - mcp/tools.py: 6 tools — list_courses, get_study_context, record_study_progress, generate_flashcards, generate_quiz, get_chapter_text (pymupdf) - Flashcard/quiz JSON validation on write (ToolError for bad input) - studyctl-mcp entry point in pyproject.toml [project.scripts] - [mcp] optional dep: mcp[cli]>=1.0.0 Agent skills (markdown prompts): - agents/claude/study-setup.md: Onboarding agent for conversational setup - agents/claude/study-generate.md: Flashcard/quiz generation skill - agents/claude/study-audio.md: TTS study audio generation Tests: 11 new (9 passed, 2 skipped for pymupdf). 593 passed, 4 skipped, 0 failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32b3bc0 commit eab3bf7

9 files changed

Lines changed: 751 additions & 2 deletions

File tree

‎agents/claude/study-audio.md‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Study Audio — TTS Study Summary Generation Skill
2+
3+
## Usage
4+
5+
```
6+
/skill:study-audio
7+
```
8+
9+
Use this skill to generate spoken study summaries from chapter content. Produces conversational audio files suitable for revision while walking, commuting, or doing chores.
10+
11+
## MCP Tools Used
12+
13+
- `get_chapter_text` — retrieve chapter content for summarisation
14+
15+
## CLI Commands Used
16+
17+
- `studyctl study-speak` — generate TTS audio from a text script
18+
19+
## Flow
20+
21+
### Step 1: Select Chapter
22+
23+
Ask the user which chapter or topic to generate audio for. Call `get_chapter_text` to retrieve the source material.
24+
25+
### Step 2: Write the Summary Script
26+
27+
Compose a spoken study summary from the chapter content. The script is plain text that will be read aloud by TTS.
28+
29+
**Script Structure:**
30+
1. **Opening hook** (1-2 sentences) — State what this chapter covers and why it matters. Start with engagement, not a dry overview.
31+
2. **Core concepts** (3-5 key ideas) — Explain each concept conversationally. Use analogies and concrete examples. Pause between concepts with transition phrases.
32+
3. **Connections** — Link concepts to each other and to prior chapters. "Remember when we talked about X? This builds on that because..."
33+
4. **Quick recall check** — Pose 2-3 questions for the listener to answer mentally. "Can you name the three types of...?" Leave a beat for thinking.
34+
5. **Wrap-up** (1-2 sentences) — Summarise the takeaway and preview what comes next.
35+
36+
**Script Writing Rules:**
37+
- Write for the ear, not the eye. Short sentences. No parenthetical asides.
38+
- Use "you" and "we" — make it feel like a conversation, not a lecture.
39+
- Avoid acronyms on first use — spell them out, then use the short form.
40+
- No markdown formatting, bullet points, or special characters — pure spoken prose.
41+
- Target 3-5 minutes of audio per chapter (~500-800 words).
42+
- Include natural transitions: "So now that we've covered X, let's look at Y."
43+
44+
**Tone Guidelines:**
45+
- Conversational and warm, like a knowledgeable friend explaining over coffee.
46+
- Confident but not condescending. Assume the listener is smart but new to this topic.
47+
- Inject genuine enthusiasm for interesting concepts. "This is where it gets clever..."
48+
- Keep energy varied — monotone kills attention. Use rhetorical questions to re-engage.
49+
50+
### Step 3: Generate Audio
51+
52+
Run `studyctl study-speak` with the script to produce the audio file. The output goes to the course's `audio/` directory.
53+
54+
```
55+
studyctl study-speak --course <name> --chapter <number> --script <script_path>
56+
```
57+
58+
Confirm the output file path and duration with the user.
59+
60+
### Step 4: Offer Iteration
61+
62+
Ask:
63+
- "Want to listen to a preview before I save the final version?"
64+
- "Should I adjust the length — shorter for a quick refresher or longer with more detail?"
65+
- "Want me to generate audio for the next chapter too?"
66+
67+
## AuDHD-Friendly Guidelines
68+
69+
- **Audio is ideal for AuDHD learners.** Movement + listening often beats sitting + reading. Frame this as a strength, not a workaround.
70+
- **Keep it short.** 3-5 minutes is the sweet spot. Anything over 7 minutes risks losing attention. Offer to split longer chapters into parts.
71+
- **Engaging beats comprehensive.** A summary that covers 80% of key ideas in an interesting way is better than a complete but dry recitation of 100%.
72+
- **Varied pacing.** Mix explanation with questions. The listener's brain needs moments to process, not just receive.
73+
- **Suggest pairing.** "Try listening to this on a walk, then do the flashcards when you get back" — multimodal reinforcement without pressure.

‎agents/claude/study-generate.md‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Study Generate — Flashcard and Quiz Generation Skill
2+
3+
## Usage
4+
5+
```
6+
/skill:study-generate
7+
```
8+
9+
Use this skill to generate flashcards and quizzes from course content. Produces AuDHD-aware study material with Socratic questioning, varied difficulty, and topic bridging.
10+
11+
## MCP Tools Used
12+
13+
- `get_chapter_text` — retrieve chapter markdown for content analysis
14+
- `generate_flashcards` — create flashcard decks from chapter content
15+
- `generate_quiz` — create multiple-choice quizzes from chapter content
16+
17+
## Flow
18+
19+
### Step 1: Select Scope
20+
21+
Ask the user what to generate for:
22+
- Specific chapter(s) or a chapter range
23+
- A topic within a chapter
24+
- A cross-chapter theme (e.g., "all networking concepts from chapters 1-4")
25+
26+
Call `get_chapter_text` for the selected scope.
27+
28+
### Step 2: Choose Output Type
29+
30+
Offer: **Flashcards**, **Quiz**, or **Both**. Default to flashcards if the user is unsure — lower stakes, faster to review.
31+
32+
### Step 3: Generate Content
33+
34+
#### Flashcards
35+
36+
Call `generate_flashcards` with the following quality rules applied:
37+
38+
**Card Structure Rules:**
39+
- Front MUST be a question, never a statement. Bad: "TCP three-way handshake". Good: "What are the three steps in a TCP handshake and why is each needed?"
40+
- Back MUST be concise — 1-3 sentences maximum. Use bullet points for multi-part answers.
41+
- Include a "why" card for every 3-4 factual cards. These ask WHY a concept works that way or WHY it matters.
42+
- Avoid yes/no questions. Prefer "how", "why", "compare", "what happens when".
43+
44+
**Difficulty Distribution (per 10 cards):**
45+
- 3 recall (define, name, list)
46+
- 4 understanding (explain, compare, distinguish)
47+
- 3 application (what would happen if, how would you, debug this)
48+
49+
**Topic Bridging Cards:**
50+
For users with networking/infrastructure background, include 1-2 bridge cards per set that connect new concepts to familiar territory. Examples:
51+
- "How does Python's garbage collector compare to how a network switch ages out MAC addresses?"
52+
- "If a Python class is like a VLAN template, what would an instance represent?"
53+
54+
#### Quizzes
55+
56+
Call `generate_quiz` with the following quality rules applied:
57+
58+
**Quiz Structure Rules:**
59+
- 4 answer choices per question (A-D)
60+
- Exactly 1 correct answer
61+
- All distractors must be plausible — no joke answers or obviously wrong options
62+
- Include a rationale for EACH choice explaining why it is correct or incorrect
63+
- Questions should test understanding, not trick the reader
64+
65+
**Rationale Format:**
66+
```
67+
Q: What does `__init__` do in a Python class?
68+
A) Imports the class module — Incorrect: imports use `import`, not `__init__`
69+
B) Initialises a new instance with starting state — Correct: called automatically on instantiation
70+
C) Deletes the instance from memory — Incorrect: that's `__del__`
71+
D) Defines the class name — Incorrect: the class name comes from the `class` statement
72+
```
73+
74+
**Difficulty Distribution (per 5 questions):**
75+
- 1 recall
76+
- 2 understanding
77+
- 2 application/scenario
78+
79+
### Step 4: Socratic Enhancement
80+
81+
After generating raw content, apply the Socratic layer:
82+
- Add 1-2 "meta" cards that ask the learner to explain a concept in their own words
83+
- Add 1 "connection" card that asks how two concepts from the chapter relate
84+
- For quizzes, add one open-ended "think about it" question at the end (no choices — just a prompt for reflection)
85+
86+
### Step 5: Review and Adjust
87+
88+
Present the generated content and ask:
89+
- "Are any of these too easy or too hard?"
90+
- "Want me to add more cards on a specific topic?"
91+
- "Should I adjust the bridging to reference different domain knowledge?"
92+
93+
Iterate based on feedback. The user controls the final set.
94+
95+
## AuDHD-Friendly Guidelines
96+
97+
- **Varied formats prevent boredom.** Mix question types within a set — do not generate 10 definition cards in a row.
98+
- **Chunk output.** Show 5 cards at a time, not 30. Ask "want more?" before continuing.
99+
- **Anchor to interests.** Networking analogies and real-world scenarios keep engagement high.
100+
- **Celebrate mastery.** If application-level cards come easily, note it: "You're thinking at the application level already — solid."
101+
- **Offer difficulty control.** "Want me to make the next set harder?" gives agency without pressure.

‎agents/claude/study-setup.md‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Study Setup — Onboarding Agent Skill
2+
3+
## Usage
4+
5+
```
6+
/skill:study-setup
7+
```
8+
9+
Use this skill when a user wants to set up studyctl for the first time, add a new course, or configure their study environment.
10+
11+
## Goal
12+
13+
Walk the user through a conversational, low-pressure onboarding flow. Gather what they're studying, where their materials live, and get them to a working first flashcard review — all without overwhelm.
14+
15+
## MCP Tools Used
16+
17+
- `list_courses` — check what's already configured
18+
- `get_study_context` — pull existing course metadata and progress
19+
20+
## CLI Commands Used
21+
22+
- `studyctl config init` — create initial configuration
23+
- `studyctl content split` — split a PDF into per-chapter markdown
24+
- `studyctl content flashcards` — generate flashcards from chapter content
25+
26+
## Flow
27+
28+
### Step 1: Check Existing State
29+
30+
Call `list_courses` first. If courses already exist, acknowledge them and ask whether the user wants to add a new course or reconfigure an existing one. Do not repeat setup steps for things already done.
31+
32+
### Step 2: Gather Study Context (Conversational)
33+
34+
Ask these questions one at a time — do not dump them all at once:
35+
36+
1. **What are you studying?** Get the course/book name, subject area, and why they're learning it (motivation helps with recall).
37+
2. **Where are your materials?** PDF path, Obsidian vault location, or other sources. Accept drag-and-drop paths.
38+
3. **Do you use NotebookLM?** If yes, ask for their project URL. If no, briefly explain what it offers (audio overviews, AI notebooks) but do not push it.
39+
40+
### Step 3: Initialise Configuration
41+
42+
Run `studyctl config init` with the gathered details. Confirm the config file location and contents with the user before proceeding.
43+
44+
### Step 4: Split Content
45+
46+
If a PDF was provided:
47+
- Run `studyctl content split --pdf <path>` to extract chapters
48+
- Show the user the chapter list and total page count
49+
- Celebrate: "Your book is ready — X chapters extracted"
50+
51+
### Step 5: Demo — First Flashcards
52+
53+
Generate sample flashcards from Chapter 1 using `studyctl content flashcards --course <name> --chapter 1`. Show 3-5 cards as a preview. Ask: "Do these look useful? Want to adjust the style?"
54+
55+
### Step 6: Confirm and Summarise
56+
57+
Print a clear summary of what was set up:
58+
- Course name and chapter count
59+
- Config file location
60+
- Next suggested action (e.g., "Run a study session with /skill:study-generate")
61+
62+
## AuDHD-Friendly Guidelines
63+
64+
- **One thing at a time.** Never present more than one question or action per message.
65+
- **Validate each step.** Confirm success before moving on. If something fails, explain clearly and offer to retry.
66+
- **No jargon without context.** If a CLI flag or concept is non-obvious, explain it in one sentence.
67+
- **Celebrate small wins.** "Chapter split complete — you're ready to study" beats a silent success.
68+
- **Offer escape hatches.** "We can skip NotebookLM setup for now and add it later" — never make optional steps feel mandatory.
69+
- **Keep messages short.** Walls of text cause context-switching fatigue. Prefer 2-4 sentences per response.

‎packages/studyctl/pyproject.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ content = ["pymupdf>=1.25", "httpx"]
1717
notebooklm = ["notebooklm-py>=0.3.4"]
1818
tui = ["textual>=0.80"]
1919
web = ["fastapi>=0.115", "uvicorn[standard]>=0.34"]
20+
mcp = ["mcp[cli]>=1.0.0"]
2021

2122
[project.scripts]
2223
studyctl = "studyctl.cli:cli"
24+
studyctl-mcp = "studyctl.mcp.server:main"
2325

2426
[project.urls]
2527
Homepage = "https://github.com/NetDevAutomate/Socratic-Study-Mentor"
@@ -36,4 +38,4 @@ packages = ["src/studyctl"]
3638
[tool.pyright]
3739
pythonVersion = "3.12"
3840
typeCheckingMode = "basic"
39-
exclude = ["src/studyctl/tui", "src/studyctl/content", "src/studyctl/cli/_content.py", "src/studyctl/web"] # optional deps not in CI
41+
exclude = ["src/studyctl/tui", "src/studyctl/content", "src/studyctl/cli/_content.py", "src/studyctl/web", "src/studyctl/mcp"] # optional deps not in CI
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""MCP server for studyctl — exposes study tools to AI coding assistants."""
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""FastMCP v1 server for studyctl.
2+
3+
Provides study tools to AI coding assistants via stdio transport.
4+
Register with: ``claude mcp add studyctl-mcp``
5+
"""
6+
7+
from __future__ import annotations
8+
9+
import sqlite3
10+
from contextlib import asynccontextmanager
11+
from dataclasses import dataclass
12+
13+
from mcp.server.fastmcp import FastMCP
14+
15+
from studyctl.settings import Settings, get_db_path, load_settings
16+
17+
18+
@dataclass
19+
class AppState:
20+
"""Shared state available to all tools via server context."""
21+
22+
db: sqlite3.Connection
23+
settings: Settings
24+
25+
26+
@asynccontextmanager
27+
async def lifespan(server: FastMCP):
28+
"""Initialize shared DB connection and settings for tool lifetime."""
29+
db_path = get_db_path()
30+
db_path.parent.mkdir(parents=True, exist_ok=True)
31+
db = sqlite3.connect(db_path)
32+
db.execute("PRAGMA journal_mode=WAL")
33+
db.execute("PRAGMA busy_timeout=5000")
34+
35+
from studyctl.review_db import ensure_tables
36+
37+
ensure_tables(db_path)
38+
39+
settings = load_settings()
40+
yield AppState(db=db, settings=settings)
41+
db.close()
42+
43+
44+
mcp = FastMCP("studyctl", lifespan=lifespan)
45+
46+
# Register tools from tools module
47+
from studyctl.mcp.tools import register_tools # noqa: E402
48+
49+
register_tools(mcp)
50+
51+
52+
def main() -> None:
53+
"""Entry point for studyctl-mcp command."""
54+
mcp.run(transport="stdio")
55+
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
 (0)