Used as the web framework to expose MCP-style tool endpoints for Pybricks documentation search and code assistance
Integrates with Pybricks GitHub repositories to access changelogs and source code documentation for version comparison features
Provides specialized documentation and code assistance for MicroPython programming, specifically tailored for Pybricks robotics development
Referenced in error handling to guide users away from incompatible desktop libraries when working with MicroPython on robotics hubs
Referenced for Pybricks package version information and to help users understand compatibility between desktop Python and MicroPython environments
Provides comprehensive documentation search, code assistance, and beginner-friendly guidance for Python programming in robotics contexts
Handles parsing and chunking of Sphinx-generated documentation from Pybricks official docs for better search indexing
Heck yes—let’s get you a working starter kit. Below are two drop-in files:
ingest_pybricks.py
— crawls the official Pybricks docs/tutorials + key GitHub pages, chunks them nicely, and builds a ChromaDB collection.mcp_server.py
— a minimal MCP-style tool server exposingdocs.search
,code.search
,snippet.suggest
, andcompare.versions
backed by that Chroma collection.
I’ve limited the crawl to the most useful, stable surfaces for beginners (API reference, parameters/constants, robotics/DriveBase, getting started, tutorials, and changelogs). You can add more later.
What we’ll ingest (initial allowlist)
- API docs (stable + latest):
docs.pybricks.com
including Robotics/DriveBase and Parameters/Constants. (Pybricks Documentation) - Getting started & IDE basics:
pybricks.com/learn/getting-started/*
,code.pybricks.com
landing. (Pybricks, Pybricks Code) - Beginner-friendly tutorials/examples: hub-to-PC and hub-to-hub comms, button basics, quick reference. (Pybricks)
- Changelogs (for version checks):
pybricks-code
andpybricks-micropython
CHANGELOGs. (GitHub) - pybricksdev docs (optional coach power tool). (Pybricks Documentation, GitHub)
1) ingest_pybricks.py
Why these sources? They’re the official, beginner-relevant places your team actually needs: API reference & constants (for method/port names) (Pybricks Documentation), how to run programs & pair hubs (classroom logistics) (Pybricks), ready-to-use tutorials and examples (frequent FLL tasks) (Pybricks), and changelogs for feature/version hints (GitHub).
2) mcp_server.py
(simple MCP-style tool server over Chroma)
This is a minimal Python FastAPI server emulating “tools” you can register with your MCP agent:
docs.search(query, filters)
— hybrid-ish dense search with optional version/source filters.code.search(symbol)
— prioritizes identifier hits.snippet.suggest(goal, hardware)
— returns a template (seeded in the index).compare.versions(feature)
— checks changelogs for mentions.
How to run it
- Ingest once (or on a schedule):
- Start the tool server:
- Hook into your MCP agent by registering these tool endpoints (your agent would call
/tools/docs.search
, etc., with JSON requests).
Next upgrades (when you have time)
- Add AST-aware chunking for Python examples you keep locally (the docs mainly contain snippets, so heading chunking works well to start).
- Reranking: after dense search, locally boost results with exact matches of tokens like
DriveBase.turn
,Port.A
,Direction.COUNTERCLOCKWISE
. - Version banner in answers using the changelog lookups so you can say “added in v3.5” (see pybricks-code / micropython changelogs). (GitHub)
If you want, I can wire this directly into your MCP agent config (whatever framework you’re using) and add a couple of few-shot answer templates tuned for FLL beginners.
Awesome goal. Here’s a lean-but-solid blueprint for an MCP-based RAG assistant tuned for beginner Python + Pybricks devs (FLL kids + coaches). I’ll pull in Pybricks-specific details from their docs/site so your assistant gives grounded, version-aware answers.
What “beginner-friendly” means here
- Speak Python, not firmware internals—explain what to import, which port to use, what the units are.
- Prefer official API calls and examples over clever hacks.
- Detect MicroPython vs CPython mismatches and nudge correctly (“this runs on the hub only”). (Pybricks Documentation, GitHub)
1) Source of truth to ingest (and keep fresh)
Minimum viable corpus:
- Official API docs (stable + latest):
- Hubs & sensors/motors, parameters/constants, robotics helpers (DriveBase). (Pybricks Documentation)
- Pybricks Code (IDE) basics: pairing, running, limits. (Pybricks Code)
- Getting started / “other editors” posts (great for setup FAQs). (Pybricks)
- Release/Changelog snippets for breaking changes or new helpers. (GitHub)
- Selected project tutorials (BLE comms, etc.) for worked examples. (Pybricks)
- Pybricks API repo/PyPI as a reference label for versions. (GitHub, PyPI)
- Landing page for a short “what is Pybricks” explainer. (Pybricks)
Practical tip: keep stable docs as default grounding, but store latest docs in a separate collection and surface a gentle version banner if answers use features newer than the team’s firmware. (Pybricks Documentation)
2) Preprocessing & chunking (works great for Markdown/HTML/Python)
Markdown/HTML docs
- Split by headings (H2/H3). Keep fenced code, tables with their captions, and any note/admonition together.
- Overlap ~80–120 tokens so definitions carry to the next chunk.
- Metadata: page URL, version (stable/latest), breadcrumbs (page → H2 → H3), any HTML
id
anchors.
Python examples/snippets
- AST or Tree-sitter per function/class, include signature + docstring + imports used.
- If a unit is long, window with ~80–120 token overlap and repeat the signature.
- Create a 2nd “interface” vector: signature + docstring only (perfect for “what does
DriveBase.turn
do?” style queries).
Why this matters for Pybricks:
- Kids search exact tokens like
Port.A
,Direction.COUNTERCLOCKWISE
,DriveBase.turn
,gears=[12,36]
. Keep those intact for keyword/rerank. (Pybricks Documentation)
3) Indexing & retrieval
- Hybrid search: dense embeddings + BM25/regex for symbol hits (
PrimeHub
,run_angle
,stalled()
). (Pybricks Documentation) - Parent–child: embed small chunks; keep a “parent” section/file to optionally expand.
- Multi-vector per chunk:
- full text, 2) headings/signature view, 3) identifiers-only (symbols, constants, error names).
- Version filter: tag each chunk
version: 3.6.1
,channel: stable/latest
,source: docs/blog/discussion
. - Rerank top-K by: exact symbol match > version proximity > doc section type (API reference > blog).
Good starting knobs:
- Chunk size 300–800 tokens for docs, 200–600 for code; overlap as above.
4) MCP server design (tools & routes)
Expose a few simple tools your agent can call:
- docs.search(query, filters) → returns passages + metadata
- Filters:
symbol
,hub=PrimeHub
,version=stable|latest
,category=motors|robotics|parameters
.
- Filters:
- code.search(symbol) → exact/regex search across examples.
- explain.error(message, context) → maps common runtime messages or gotchas to fixes (e.g., wrong port, MicroPython import).
- snippet.suggest(goal, hardware) → templates (see §7).
- compare.versions(feature) → show when something was added/changed (reads changelogs). (GitHub)
Optional power-ups:
- pybricksdev bridge for scripted flashing/log retrieval (coach use only). (GitHub)
5) Guardrails & beginner heuristics
- MicroPython ≠ CPython: if user tries
pip install
/desktop-only libs, return a helpful correction and suggest the Pybricks way or hub-to-PC comms. (GitHub) - Units & sign conventions: explain degrees vs deg/s, positive means clockwise/right, etc., with short examples. (Pybricks Documentation)
- Hardware sanity: warn if method requires certain sensors or hubs; confirm which hub (Prime/Inventor/Technic). (Pybricks Documentation)
- Version banner: “This answer uses feature added in v3.2.0… consider updating” (e.g.,
DriveBase.stalled()
mention). (GitHub)
6) Answer patterns (prompt templates for your agent)
A) “How do I…?” (action recipe)
System hint: prefer official API + short code + 2 gotcha bullets.
Template (few-shot)
Goal: Drive straight 300 mm, then turn right 90°. Hardware: PrimeHub, 2 motors on A/B, wheel_diameter=56, axle_track=114. Answer:
- Imports + setup; 2) Code; 3) Notes on signs/units; 4) Link to docs.
Generated answer should resemble:
Notes: positive = forward/right; measure diameter/track for accuracy. (Pybricks Documentation)
B) “What does this error mean?”
- Search error text; map to common causes.
- Offer fix + 1-line explanation + tiny example.
C) “Why isn’t my motor moving?”
Checklist: correct Port, Direction
, gear list shape, stall/hold behavior, power limits. Provide a run_angle
demo and link to Motor docs. (Pybricks Documentation)
D) “Which port constant do I use?”
Answer with Port.A/B/C/D
and mention sensor vs motor ports on their hub; link to parameters/constants. (Pybricks Documentation)
7) Prebuilt snippet templates (your snippet.suggest
tool)
Seed a few common tasks (return parameterized code):
- DriveBase skeleton (takes wheel_diameter, axle_track). (Pybricks Documentation)
- Single motor move by angle/speed (with
Direction
&gears
examples). (Pybricks Documentation) - Read hub orientation / display light / buttons (Prime Hub basics). (Pybricks Documentation)
- Broadcast between hubs / BLE example for advanced kids. (Pybricks Documentation, Pybricks)
Each template should embed short comments like “units: deg/s, mm; +angle = right turn”.
8) Evaluation plan (coach-friendly)
Make a tiny test set of 25 real questions your kids ask. Examples:
- “How do I set up
DriveBase
and turn 45°?” (Pybricks Documentation) - “What does
Direction.COUNTERCLOCKWISE
change?” (Pybricks Documentation) - “Why does +90 turn right on our robot?” (Pybricks Documentation)
- “How do I gear down a motor in code?” (
gears=[12,36]
example). (Pybricks Documentation) - “Which ports are valid on Prime Hub?” (A–F for motors, etc.). (Pybricks Documentation)
- “Can I
pip install
numpy?” (explain hub MicroPython limits). (GitHub) - “How to check if the robot is stalled?” (
DriveBase.stalled()
availability). (GitHub)
Score each answer for correctness, actionable code, cites present, beginner clarity. Iterate chunk sizes and reranker.
9) Ops: keeping it current
- Weekly crawl of “stable” docs; monthly for “latest”.
- Watch pybricks-code and pybricks-micropython changelogs for features that change beginner UX (e.g., new
DriveBase
helpers). (GitHub) - If a change conflicts with an existing snippet, mark snippet with a version guard.
10) Quick pitfalls your assistant should proactively catch
- Suggesting desktop-only libraries or features not on the hub. (GitHub)
- Mixing SPIKE/Inventor vs Technic hub specifics without checking the hub. (Pybricks Documentation)
- Getting sign conventions wrong for turns/speeds. (Pybricks Documentation)
- Forgetting to include
gears
or misunderstand its list-of-lists format. (Pybricks Documentation)
11) Day-one stack recommendation
- Embedder: any strong general code/text embedding works; you don’t need a code-only model for doc QA.
- Index: pgvector/FAISS (two collections: “api_docs” + “examples/snippets”).
- Rerank: small BM25 over the top-50 dense hits + symbol regex bonus.
- Caching: store resolved answers (code + citations) per question for classroom speed.
If you want, I can:
- generate a starter ingestion script (scrapes the specific doc sections above, chunks them with the rules here, and builds a pgvector index), and
- stub MCP tool definitions (
docs.search
,snippet.suggest
, etc.) you can drop into your server.
Tell me your preferred DB (FAISS vs pgvector) and I’ll hand you the code.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables beginner-friendly Python and Pybricks development support through RAG-powered tools that search official documentation, suggest code snippets, and provide version-aware guidance for LEGO robotics programming.
- 1. ingest_pybricks.py
- 2. mcp_server.py (simple MCP-style tool server over Chroma)
- How to run it
- Next upgrades (when you have time)
- What “beginner-friendly” means here
- 1. Source of truth to ingest (and keep fresh)
- 2. Preprocessing & chunking (works great for Markdown/HTML/Python)
- 3. Indexing & retrieval
- 4. MCP server design (tools & routes)
- 5. Guardrails & beginner heuristics
- 6. Answer patterns (prompt templates for your agent)
- 7. Prebuilt snippet templates (your snippet.suggesttool)
- 8. Evaluation plan (coach-friendly)
- 9. Ops: keeping it current
- 10. Quick pitfalls your assistant should proactively catch
- 11. Day-one stack recommendation
Related MCP Servers
- AsecurityAlicenseAqualityFacilitates searching and accessing programming resources across platforms like Stack Overflow, MDN, GitHub, npm, and PyPI, aiding LLMs in finding code examples and documentation.Last updated -638JavaScriptAGPL 3.0
- AsecurityAlicenseAqualityEnables AI assistants to interact with GitHub through the PyGithub library, providing tools for managing issues, repositories, pull requests, and other GitHub operations with intelligent parameter handling and error management.Last updated -191PythonMIT License
- -securityFlicense-qualityA modular tool that combines RAG-based retrieval with Pinecone vector storage to create intelligent assistants capable of answering domain-specific questions from your knowledge base.Last updated -Python
- AsecurityFlicenseAqualityAI-powered code assistant that provides advanced search and discovery capabilities across GitHub and NPM ecosystems, helping users understand code patterns, implementations, and connections between repositories.Last updated -10526344TypeScript