solidworks_mcp.ui.services.docs_service¶
solidworks_mcp.ui.services.docs_service ¶
Docs context fetching and RAG ingestion for the Prefab CAD dashboard.
Responsibilities (Single Responsibility principle):
- Fetch and filter docs from the MCP docs endpoint (fetch_docs_context).
- Ingest local files or URLs into the simple retrieval index (ingest_reference_source).
Does NOT own: LLM calls, preview export, session state mutation beyond metadata merges.
Attributes¶
DEFAULT_API_ORIGIN
module-attribute
¶
Classes¶
HTMLTextExtractor ¶
Bases: HTMLParser
Minimal HTML-to-plain-text extractor.
Strips tags and collects visible text content. Script, style, and nav elements are suppressed entirely.
Source code in src/solidworks_mcp/ui/services/_utils.py
Functions¶
_chunk_text ¶
Split long text into overlapping chunks for simple local retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text processed by the operation. |
required |
chunk_size
|
int
|
Maximum number of characters to keep in each chunk. Defaults to 1000. |
1000
|
overlap
|
int
|
Number of overlapping characters between chunks. Defaults to 150. |
150
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/retrieval_index.py
fetch_docs_context ¶
fetch_docs_context(session_id: str, *, docs_query: str = '', db_path: Path | None = None, api_origin: str = DEFAULT_API_ORIGIN) -> dict[str, Any]
Fetch docs text from the /docs endpoint and store a filtered context snippet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
docs_query
|
str
|
Keyword(s) to filter the docs text by. |
''
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
api_origin
|
str
|
Base URL of the running FastAPI server. |
DEFAULT_API_ORIGIN
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/docs_service.py
filter_docs_text ¶
Filter plain-text docs content to lines most relevant to query.
Returns up to max_chars characters of the most relevant lines, scored
by how many query tokens they contain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Full plain-text docs content. |
required |
query
|
str
|
Space-separated keyword query. |
required |
max_chars
|
int
|
Maximum characters to return. |
4000
|
Returns:
| Type | Description |
|---|---|
str
|
Filtered and truncated text snippet. |
Source code in src/solidworks_mcp/ui/services/_utils.py
ingest_reference_source ¶
ingest_reference_source(session_id: str, *, source_path: str, namespace: str, chunk_size: int = 1200, overlap: int = 200, db_path: Path | None = None) -> dict[str, Any]
Ingest a local file or URL into the simple local retrieval index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Dashboard session identifier. |
required |
source_path
|
str
|
Absolute file path or http/https URL. |
required |
namespace
|
str
|
Namespace key that isolates this index from others. |
required |
chunk_size
|
int
|
Maximum characters per chunk. |
1200
|
overlap
|
int
|
Overlapping characters between adjacent chunks. |
200
|
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Full dashboard state payload. |
Source code in src/solidworks_mcp/ui/services/docs_service.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
insert_evidence_link ¶
insert_evidence_link(*, session_id: str, source_type: str, source_id: str, checkpoint_id: int | None = None, relevance_score: float | None = None, rationale: str | None = None, payload_json: str | None = None, db_path: Path | None = None) -> None
Insert one evidence row used by planning/classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
source_type
|
str
|
The source type value. |
required |
source_id
|
str
|
The source id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
relevance_score
|
float | None
|
The relevance score value. Defaults to None. |
None
|
rationale
|
str | None
|
The rationale value. Defaults to None. |
None
|
payload_json
|
str | None
|
The payload json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_tool_call_record ¶
insert_tool_call_record(*, session_id: str, tool_name: str, checkpoint_id: int | None = None, run_id: str | None = None, input_json: str | None = None, output_json: str | None = None, success: bool = True, latency_ms: float | None = None, db_path: Path | None = None) -> None
Insert one tool call execution record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
tool_name
|
str
|
The tool name value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
run_id
|
str | None
|
The run id value. Defaults to None. |
None
|
input_json
|
str | None
|
The input json value. Defaults to None. |
None
|
output_json
|
str | None
|
The output json value. Defaults to None. |
None
|
success
|
bool
|
The success value. Defaults to True. |
True
|
latency_ms
|
float | None
|
The latency ms value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
is_url_reference ¶
Return True when source_path is an http/https URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
str
|
Raw source path string from the UI. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/solidworks_mcp/ui/services/_utils.py
merge_metadata ¶
merge_metadata(session_id: str, *, db_path: Path | None = None, user_goal: str | None = None, **updates: Any) -> dict[str, Any]
Read session metadata, merge updates into it, and write it back.
Implements the optimistic read-modify-write pattern used across all service functions that need to update one or more metadata keys without overwriting unrelated keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session identifier. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
user_goal
|
str | None
|
When provided, also updates the |
None
|
**updates
|
Any
|
Arbitrary key-value pairs to merge into metadata. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged metadata dict after the write. |
Source code in src/solidworks_mcp/ui/services/_utils.py
persist_ui_action ¶
persist_ui_action(session_id: str, *, tool_name: str, db_path: Path | None = None, metadata_updates: dict[str, Any] | None = None, user_goal: str | None = None, input_payload: dict[str, Any] | None = None, output_payload: dict[str, Any] | None = None, output_metadata: bool = False, success: bool = True, checkpoint_id: int | None = None) -> dict[str, Any]
Persist metadata updates and a matching tool-call audit record atomically.
Combines :func:merge_metadata and insert_tool_call_record so callers
can update session state and write an audit entry in a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session identifier. |
required |
tool_name
|
str
|
Logical name for the audit record (e.g. |
required |
db_path
|
Path | None
|
Optional override for the SQLite database path. |
None
|
metadata_updates
|
dict[str, Any] | None
|
Key-value pairs to merge into session metadata. |
None
|
user_goal
|
str | None
|
When provided, also updates the |
None
|
input_payload
|
dict[str, Any] | None
|
Dict serialised as the |
None
|
output_payload
|
dict[str, Any] | None
|
Dict serialised as the |
None
|
output_metadata
|
bool
|
When |
False
|
success
|
bool
|
Whether the action succeeded. |
True
|
checkpoint_id
|
int | None
|
Optional FK to the associated plan checkpoint. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged metadata dict after the write. |
Source code in src/solidworks_mcp/ui/services/_utils.py
read_reference_source ¶
Read the text content of a local file (PDF, markdown, text).
PDF extraction requires the optional pypdf package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
Path
|
Local file path to read. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Extracted plain text content. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When a PDF is supplied but |
Source code in src/solidworks_mcp/ui/services/_utils.py
read_reference_url ¶
Fetch content from a URL and return (text, label).
Handles HTML (stripped), PDF (requires pypdf), and plain text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_url
|
str
|
http/https URL to fetch. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (plain_text_content, label) where label is derived from the URL path. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
When a PDF is served but |
Source code in src/solidworks_mcp/ui/services/_utils.py
sanitize_ui_text ¶
Return a clean string from value, using fallback for empty/invalid inputs.
Strips template placeholders such as {{ field }}, bare quotes, and
pydantic-ai expression strings that sometimes leak into UI state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Arbitrary input (str, None, etc.). |
required |
fallback
|
str
|
Value to return when value is empty or invalid. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Cleaned string, or fallback. |