This knowledge base provides comprehensive documentation for creating CAD expert AI agents that understand Onshape API and professional CAD practices.
knowledge_base/
├── api/ # Onshape REST API documentation
│ └── onshape_api_overview.md
├── cad/ # CAD principles and best practices
│ └── cad_best_practices.md
├── examples/ # Real-world design examples
│ └── parametric_bracket.md
└── README.md # This file
The knowledge base files serve as:
- Reference Material - Quick lookups for API syntax and CAD patterns
- Training Examples - Real-world scenarios and solutions
- Best Practices - Professional guidelines and standards
- Design Patterns - Reusable approaches to common problems
Add to your server.py:
@app.list_resources()
async def list_resources() -> list[Resource]:
"""Provide knowledge base as MCP resources."""
resources = []
kb_path = Path(__file__).parent.parent / "knowledge_base"
for md_file in kb_path.glob("**/*.md"):
if md_file.name == "README.md":
continue
relative_path = md_file.relative_to(kb_path)
resources.append(Resource(
uri=f"onshape://kb/{relative_path}",
name=md_file.stem.replace('_', ' ').title(),
description=f"Knowledge: {md_file.stem}",
mimeType="text/markdown"
))
return resources
@app.read_resource()
async def read_resource(uri: str) -> str:
"""Read knowledge base content."""
if not uri.startswith("onshape://kb/"):
raise ValueError("Invalid resource URI")
kb_path = Path(__file__).parent.parent / "knowledge_base"
file_path = kb_path / uri.replace("onshape://kb/", "")
if not file_path.exists():
raise FileNotFoundError(f"Resource not found: {uri}")
return file_path.read_text()Claude can then read these files during conversations!
If you have Claude Pro/Teams:
- Create a project called "Onshape CAD Expert"
- Upload all
.mdfiles from this knowledge base - Claude has access to all content in every conversation
Reference key content in your system prompt:
You have access to comprehensive Onshape knowledge:
- API Overview: Complete REST API reference
- CAD Best Practices: Professional CAD guidelines
- Design Examples: Real-world parametric designs
Refer to these resources when:
- Users ask about API usage
- Designing new features
- Following best practices
- Creating parametric modelsonshape_api_overview.md
- API structure and authentication
- Document hierarchy (document → workspace → element)
- Key endpoints for all operations
- Feature JSON structure reference
- Parameter types and examples
- Variables and expressions syntax
- Common patterns and best practices
- Standard plane IDs and queries
What It Covers:
- ✅ All major API endpoints
- ✅ JSON structure for features
- ✅ Variable and expression syntax
- ✅ Query types and references
- ✅ Common patterns
- ✅ Error handling
cad_best_practices.md
- Parametric design principles
- Design intent documentation
- Feature organization strategies
- Sketch best practices
- Variable usage guidelines
- Pattern creation
- Fillet and chamfer strategies
- Design for Manufacturing (DFM)
- Performance optimization
- Assembly best practices
- Common mistakes to avoid
What It Covers:
- ✅ Professional CAD workflows
- ✅ Parametric modeling techniques
- ✅ Feature naming and organization
- ✅ Manufacturing considerations
- ✅ Material-specific guidelines
- ✅ Quality checklists
parametric_bracket.md
- Complete L-bracket design
- Variable table with descriptions
- Full feature sequence
- Design validation tests
- Manufacturing notes
- Design variations
- Key takeaways
What It Covers:
- ✅ End-to-end design example
- ✅ Complete variable table
- ✅ Logical feature sequence
- ✅ Testing and validation
- ✅ Manufacturing process
- ✅ Design variations
-
API Documentation
# Add new API endpoint docs knowledge_base/api/assemblies_api.md knowledge_base/api/drawings_api.md knowledge_base/api/metadata_api.md -
CAD Guides
# Add specific CAD topics knowledge_base/cad/sheet_metal_design.md knowledge_base/cad/plastic_part_design.md knowledge_base/cad/assembly_strategies.md -
Examples
# Add more design examples knowledge_base/examples/enclosure_design.md knowledge_base/examples/gear_assembly.md knowledge_base/examples/sheet_metal_box.md
Good Knowledge Base Content:
- ✅ Accurate and tested
- ✅ Well-organized with clear headers
- ✅ Includes code examples
- ✅ Explains the "why" not just "how"
- ✅ Covers edge cases
- ✅ Includes best practices
- ✅ References official docs
Content Template:
# Topic Name
## Overview
Brief description of what this covers
## Key Concepts
Main ideas and principles
## Syntax/Structure
How to use it (with examples)
## Examples
Real-world usage examples
## Best Practices
Professional guidelines
## Common Mistakes
What to avoid
## Resources
Links to official docsTo add official Onshape docs:
import requests
from bs4 import BeautifulSoup
from markdownify import markdownify
def scrape_onshape_page(url: str, output_file: str):
"""Scrape and convert Onshape docs to markdown."""
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
# Extract main content
content = soup.find('main') or soup.find('article')
# Convert to markdown
markdown = markdownify(str(content))
# Save
Path(output_file).write_text(markdown)
# Scrape key pages
pages = {
"api-intro": "https://onshape-public.github.io/docs/api-intro/",
"partstudios": "https://onshape-public.github.io/docs/partstudios/",
# Add more...
}
for name, url in pages.items():
scrape_onshape_page(url, f"knowledge_base/api/{name}.md")For semantic search over large documentation:
from sentence_transformers import SentenceTransformer
import faiss
class KnowledgeBaseRAG:
def __init__(self, kb_path: str):
self.model = SentenceTransformer('all-MiniLM-L6-v2')
self.index_knowledge_base(kb_path)
def index_knowledge_base(self, kb_path: str):
"""Create embeddings for all docs."""
texts = []
for md_file in Path(kb_path).glob("**/*.md"):
content = md_file.read_text()
# Split into chunks
chunks = self.chunk_text(content, chunk_size=500)
texts.extend(chunks)
# Create FAISS index
embeddings = self.model.encode(texts)
self.index = faiss.IndexFlatL2(embeddings.shape[1])
self.index.add(embeddings)
self.docs = texts
def search(self, query: str, k: int = 3):
"""Find relevant documentation."""
query_emb = self.model.encode([query])
distances, indices = self.index.search(query_emb, k)
return [self.docs[i] for i in indices[0]]-
Monthly Review
- Check for API changes
- Update deprecated patterns
- Add new features
-
User Feedback
- Add frequently asked topics
- Clarify confusing sections
- Expand examples
-
Onshape Releases
- Review release notes
- Update affected docs
- Add new capabilities
- All code examples tested
- Links to official docs valid
- Markdown formatting correct
- Consistent terminology
- No outdated information
To add content:
- Choose appropriate directory (
api/,cad/, orexamples/) - Create
.mdfile with descriptive name - Follow content template
- Include code examples
- Add references to official docs
- Test all examples
- Update this README if adding new category
- Professional CAD standards (ASME Y14.5, ISO 128)
- Manufacturing process guides
- Material specifications
- Industry best practices
- Start Using: Reference this KB when helping users
- Expand Content: Add more examples and guides
- Implement RAG: Add semantic search for large docs
- Gather Feedback: Learn what content is most useful
- Keep Updated: Maintain as Onshape evolves
The knowledge base is a living resource that grows with your needs!