kicad-sch-api 0.4.1__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kicad_sch_api/__init__.py +67 -2
- kicad_sch_api/cli/kicad_to_python.py +169 -0
- kicad_sch_api/collections/__init__.py +23 -8
- kicad_sch_api/collections/base.py +369 -59
- kicad_sch_api/collections/components.py +1376 -187
- kicad_sch_api/collections/junctions.py +129 -289
- kicad_sch_api/collections/labels.py +391 -287
- kicad_sch_api/collections/wires.py +202 -316
- kicad_sch_api/core/__init__.py +37 -2
- kicad_sch_api/core/component_bounds.py +34 -12
- kicad_sch_api/core/components.py +146 -7
- kicad_sch_api/core/config.py +25 -12
- kicad_sch_api/core/connectivity.py +692 -0
- kicad_sch_api/core/exceptions.py +175 -0
- kicad_sch_api/core/factories/element_factory.py +3 -1
- kicad_sch_api/core/formatter.py +24 -7
- kicad_sch_api/core/geometry.py +94 -5
- kicad_sch_api/core/managers/__init__.py +4 -0
- kicad_sch_api/core/managers/base.py +76 -0
- kicad_sch_api/core/managers/file_io.py +3 -1
- kicad_sch_api/core/managers/format_sync.py +3 -2
- kicad_sch_api/core/managers/graphics.py +3 -2
- kicad_sch_api/core/managers/hierarchy.py +661 -0
- kicad_sch_api/core/managers/metadata.py +4 -2
- kicad_sch_api/core/managers/sheet.py +52 -14
- kicad_sch_api/core/managers/text_elements.py +3 -2
- kicad_sch_api/core/managers/validation.py +3 -2
- kicad_sch_api/core/managers/wire.py +112 -54
- kicad_sch_api/core/parsing_utils.py +63 -0
- kicad_sch_api/core/pin_utils.py +103 -9
- kicad_sch_api/core/schematic.py +343 -29
- kicad_sch_api/core/types.py +79 -7
- kicad_sch_api/exporters/__init__.py +10 -0
- kicad_sch_api/exporters/python_generator.py +610 -0
- kicad_sch_api/exporters/templates/default.py.jinja2 +65 -0
- kicad_sch_api/geometry/__init__.py +15 -3
- kicad_sch_api/geometry/routing.py +211 -0
- kicad_sch_api/parsers/elements/label_parser.py +30 -8
- kicad_sch_api/parsers/elements/symbol_parser.py +255 -83
- kicad_sch_api/utils/logging.py +555 -0
- kicad_sch_api/utils/logging_decorators.py +587 -0
- kicad_sch_api/utils/validation.py +16 -22
- kicad_sch_api/wrappers/__init__.py +14 -0
- kicad_sch_api/wrappers/base.py +89 -0
- kicad_sch_api/wrappers/wire.py +198 -0
- kicad_sch_api-0.5.1.dist-info/METADATA +540 -0
- kicad_sch_api-0.5.1.dist-info/RECORD +114 -0
- kicad_sch_api-0.5.1.dist-info/entry_points.txt +4 -0
- {kicad_sch_api-0.4.1.dist-info → kicad_sch_api-0.5.1.dist-info}/top_level.txt +1 -0
- mcp_server/__init__.py +34 -0
- mcp_server/example_logging_integration.py +506 -0
- mcp_server/models.py +252 -0
- mcp_server/server.py +357 -0
- mcp_server/tools/__init__.py +32 -0
- mcp_server/tools/component_tools.py +516 -0
- mcp_server/tools/connectivity_tools.py +532 -0
- mcp_server/tools/consolidated_tools.py +1216 -0
- mcp_server/tools/pin_discovery.py +333 -0
- mcp_server/utils/__init__.py +38 -0
- mcp_server/utils/logging.py +127 -0
- mcp_server/utils.py +36 -0
- kicad_sch_api-0.4.1.dist-info/METADATA +0 -491
- kicad_sch_api-0.4.1.dist-info/RECORD +0 -87
- kicad_sch_api-0.4.1.dist-info/entry_points.txt +0 -2
- {kicad_sch_api-0.4.1.dist-info → kicad_sch_api-0.5.1.dist-info}/WHEEL +0 -0
- {kicad_sch_api-0.4.1.dist-info → kicad_sch_api-0.5.1.dist-info}/licenses/LICENSE +0 -0
mcp_server/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""KiCAD Schematic API - MCP Server Package
|
|
2
|
+
|
|
3
|
+
This package contains the Model Context Protocol (MCP) server implementation
|
|
4
|
+
for the kicad-sch-api library.
|
|
5
|
+
|
|
6
|
+
Main features:
|
|
7
|
+
- Tool implementations for schematic manipulation
|
|
8
|
+
- Integrated logging framework
|
|
9
|
+
- Performance monitoring
|
|
10
|
+
- Error handling and recovery
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from mcp_server.utils import (
|
|
14
|
+
configure_mcp_logging,
|
|
15
|
+
get_mcp_logger,
|
|
16
|
+
)
|
|
17
|
+
from mcp_server.models import (
|
|
18
|
+
PointModel,
|
|
19
|
+
PinInfoOutput,
|
|
20
|
+
ComponentPinsOutput,
|
|
21
|
+
ComponentInfoOutput,
|
|
22
|
+
ErrorOutput,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
__all__ = [
|
|
27
|
+
"configure_mcp_logging",
|
|
28
|
+
"get_mcp_logger",
|
|
29
|
+
"PointModel",
|
|
30
|
+
"PinInfoOutput",
|
|
31
|
+
"ComponentPinsOutput",
|
|
32
|
+
"ComponentInfoOutput",
|
|
33
|
+
"ErrorOutput",
|
|
34
|
+
]
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
"""Example MCP server implementation with integrated logging.
|
|
2
|
+
|
|
3
|
+
This module demonstrates how to integrate the logging framework into an MCP server.
|
|
4
|
+
Shows practical examples of:
|
|
5
|
+
- Tool implementation with logging
|
|
6
|
+
- Error handling with logging
|
|
7
|
+
- Performance monitoring
|
|
8
|
+
- Component-specific logging
|
|
9
|
+
- Log analysis and searching
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Dict, Optional
|
|
14
|
+
import logging
|
|
15
|
+
|
|
16
|
+
# Import logging utilities
|
|
17
|
+
from mcp_server.utils import (
|
|
18
|
+
configure_mcp_logging,
|
|
19
|
+
get_mcp_logger,
|
|
20
|
+
log_operation,
|
|
21
|
+
log_timing,
|
|
22
|
+
log_errors,
|
|
23
|
+
operation_context,
|
|
24
|
+
ComponentLogger,
|
|
25
|
+
OperationTimer,
|
|
26
|
+
search_logs,
|
|
27
|
+
LogQuery,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# ============================================================================
|
|
32
|
+
# INITIALIZATION
|
|
33
|
+
# ============================================================================
|
|
34
|
+
|
|
35
|
+
def setup_server():
|
|
36
|
+
"""Initialize MCP server with logging."""
|
|
37
|
+
print("Initializing MCP server...")
|
|
38
|
+
|
|
39
|
+
# Configure logging
|
|
40
|
+
configure_mcp_logging(
|
|
41
|
+
log_dir=Path("logs"),
|
|
42
|
+
debug_level=True, # Development: verbose
|
|
43
|
+
json_format=False # Development: human-readable
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
logger = get_mcp_logger()
|
|
47
|
+
logger.info("MCP server initialized")
|
|
48
|
+
return logger
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# ============================================================================
|
|
52
|
+
# EXAMPLE 1: Simple Tool Implementation
|
|
53
|
+
# ============================================================================
|
|
54
|
+
|
|
55
|
+
logger = get_mcp_logger("tools")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@log_operation(operation_name="create_schematic")
|
|
59
|
+
@log_timing(threshold_ms=100)
|
|
60
|
+
def tool_create_schematic(name: str) -> Dict[str, Any]:
|
|
61
|
+
"""Create a new schematic.
|
|
62
|
+
|
|
63
|
+
Example:
|
|
64
|
+
result = tool_create_schematic("MyCircuit")
|
|
65
|
+
# Logs: "START: create_schematic"
|
|
66
|
+
# Logs: "Schematic created: MyCircuit"
|
|
67
|
+
# Logs: "COMPLETE: create_schematic (15.23ms)"
|
|
68
|
+
"""
|
|
69
|
+
with operation_context("create_schematic", details={"name": name}):
|
|
70
|
+
logger.debug(f"Creating schematic: {name}")
|
|
71
|
+
|
|
72
|
+
# Simulate schematic creation
|
|
73
|
+
schematic = {
|
|
74
|
+
"uuid": "abc123",
|
|
75
|
+
"name": name,
|
|
76
|
+
"components": [],
|
|
77
|
+
"wires": [],
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
logger.info(f"Schematic created: {name}")
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
"success": True,
|
|
84
|
+
"schematic": schematic,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# ============================================================================
|
|
89
|
+
# EXAMPLE 2: Component Operations with Logging
|
|
90
|
+
# ============================================================================
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@log_operation(operation_name="add_resistor")
|
|
94
|
+
def tool_add_resistor(
|
|
95
|
+
schematic_uuid: str,
|
|
96
|
+
reference: str,
|
|
97
|
+
value: str,
|
|
98
|
+
tolerance: Optional[str] = None,
|
|
99
|
+
) -> Dict[str, Any]:
|
|
100
|
+
"""Add resistor to schematic.
|
|
101
|
+
|
|
102
|
+
Example:
|
|
103
|
+
result = tool_add_resistor("abc123", "R1", "10k", "1%")
|
|
104
|
+
# Logs all operations with [R1] context
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
with ComponentLogger(reference) as comp_logger:
|
|
108
|
+
comp_logger.debug("Initializing resistor")
|
|
109
|
+
|
|
110
|
+
# Simulate component addition
|
|
111
|
+
component = {
|
|
112
|
+
"uuid": f"comp_{reference}",
|
|
113
|
+
"reference": reference,
|
|
114
|
+
"value": value,
|
|
115
|
+
"tolerance": tolerance,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
comp_logger.debug(f"Set value to {value}")
|
|
119
|
+
comp_logger.debug(f"Set tolerance to {tolerance}")
|
|
120
|
+
comp_logger.info("Resistor created successfully")
|
|
121
|
+
|
|
122
|
+
# Log component history
|
|
123
|
+
history = comp_logger.get_history()
|
|
124
|
+
logger.debug(f"Component {reference} operations: {len(history)}")
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
"success": True,
|
|
128
|
+
"component": component,
|
|
129
|
+
"summary": comp_logger.summary(),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# ============================================================================
|
|
134
|
+
# EXAMPLE 3: Multi-Step Operation
|
|
135
|
+
# ============================================================================
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def tool_build_circuit(schematic_uuid: str, config: Dict[str, Any]) -> Dict[str, Any]:
|
|
139
|
+
"""Build circuit with multiple components.
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
result = tool_build_circuit("abc123", {
|
|
143
|
+
"components": [
|
|
144
|
+
{"ref": "R1", "value": "10k"},
|
|
145
|
+
{"ref": "R2", "value": "20k"},
|
|
146
|
+
]
|
|
147
|
+
})
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
with operation_context("build_circuit", details=config):
|
|
151
|
+
logger.info("Building circuit")
|
|
152
|
+
|
|
153
|
+
results = []
|
|
154
|
+
|
|
155
|
+
# Process each component
|
|
156
|
+
for comp_config in config.get("components", []):
|
|
157
|
+
comp_ref = comp_config["ref"]
|
|
158
|
+
|
|
159
|
+
with ComponentLogger(comp_ref) as comp_logger:
|
|
160
|
+
comp_logger.debug("Adding component")
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
# Simulate component addition
|
|
164
|
+
result = {
|
|
165
|
+
"reference": comp_ref,
|
|
166
|
+
"value": comp_config.get("value"),
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
comp_logger.info("Component added successfully")
|
|
170
|
+
results.append(result)
|
|
171
|
+
|
|
172
|
+
except Exception as e:
|
|
173
|
+
comp_logger.error(f"Failed to add component: {e}")
|
|
174
|
+
raise
|
|
175
|
+
|
|
176
|
+
logger.info(f"Circuit built with {len(results)} components")
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
"success": True,
|
|
180
|
+
"components_added": len(results),
|
|
181
|
+
"components": results,
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
# ============================================================================
|
|
186
|
+
# EXAMPLE 4: Error Handling
|
|
187
|
+
# ============================================================================
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@log_errors(operation_name="get_pin_position")
|
|
191
|
+
def tool_get_pin_position(
|
|
192
|
+
schematic_uuid: str,
|
|
193
|
+
component_ref: str,
|
|
194
|
+
pin_num: int,
|
|
195
|
+
) -> Dict[str, Any]:
|
|
196
|
+
"""Get pin position with comprehensive error logging.
|
|
197
|
+
|
|
198
|
+
Example:
|
|
199
|
+
# Valid call
|
|
200
|
+
result = tool_get_pin_position("abc123", "R1", 1)
|
|
201
|
+
|
|
202
|
+
# Invalid call - logs error
|
|
203
|
+
result = tool_get_pin_position("abc123", "R1", -1)
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
with operation_context(
|
|
207
|
+
"get_pin_position",
|
|
208
|
+
component=component_ref,
|
|
209
|
+
details={"pin": pin_num},
|
|
210
|
+
):
|
|
211
|
+
logger.debug(f"Getting pin {pin_num} for {component_ref}")
|
|
212
|
+
|
|
213
|
+
# Validate pin number
|
|
214
|
+
if pin_num < 1:
|
|
215
|
+
raise ValueError(f"Invalid pin number: {pin_num}")
|
|
216
|
+
|
|
217
|
+
# Simulate pin position lookup
|
|
218
|
+
position = {
|
|
219
|
+
"x": 100.0 + (pin_num * 2.54),
|
|
220
|
+
"y": 100.0,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
logger.info(f"Pin {pin_num} position: {position}")
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
"success": True,
|
|
227
|
+
"component": component_ref,
|
|
228
|
+
"pin": pin_num,
|
|
229
|
+
"position": position,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
# ============================================================================
|
|
234
|
+
# EXAMPLE 5: Performance Monitoring
|
|
235
|
+
# ============================================================================
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@log_timing(threshold_ms=500)
|
|
239
|
+
def tool_analyze_circuit(schematic_uuid: str) -> Dict[str, Any]:
|
|
240
|
+
"""Analyze circuit with performance monitoring.
|
|
241
|
+
|
|
242
|
+
Example:
|
|
243
|
+
result = tool_analyze_circuit("abc123")
|
|
244
|
+
# Logs timing, warns if > 500ms
|
|
245
|
+
"""
|
|
246
|
+
|
|
247
|
+
with OperationTimer("circuit_analysis", threshold_ms=500):
|
|
248
|
+
logger.info("Starting circuit analysis")
|
|
249
|
+
|
|
250
|
+
# Simulate analysis steps
|
|
251
|
+
analysis = {
|
|
252
|
+
"component_count": 5,
|
|
253
|
+
"wire_count": 4,
|
|
254
|
+
"nets": ["VCC", "GND"],
|
|
255
|
+
"errors": 0,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
logger.debug(f"Found {analysis['component_count']} components")
|
|
259
|
+
logger.debug(f"Found {analysis['wire_count']} wires")
|
|
260
|
+
logger.info("Circuit analysis complete")
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
"success": True,
|
|
264
|
+
"analysis": analysis,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
# ============================================================================
|
|
269
|
+
# EXAMPLE 6: Logging Search and Analysis
|
|
270
|
+
# ============================================================================
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def analyze_logs() -> Dict[str, Any]:
|
|
274
|
+
"""Analyze logs for debugging and monitoring.
|
|
275
|
+
|
|
276
|
+
Example:
|
|
277
|
+
result = analyze_logs()
|
|
278
|
+
print(f"Total operations: {result['total_operations']}")
|
|
279
|
+
print(f"Errors: {result['error_count']}")
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
log_path = Path("logs/mcp_server.log")
|
|
283
|
+
|
|
284
|
+
if not log_path.exists():
|
|
285
|
+
logger.warning("Log file not found")
|
|
286
|
+
return {"error": "Log file not found"}
|
|
287
|
+
|
|
288
|
+
logger.info("Analyzing logs")
|
|
289
|
+
|
|
290
|
+
# Find errors
|
|
291
|
+
errors = search_logs(log_path, level="ERROR", limit=100)
|
|
292
|
+
logger.debug(f"Found {len(errors)} errors")
|
|
293
|
+
|
|
294
|
+
# Find slow operations
|
|
295
|
+
slow_ops = (
|
|
296
|
+
LogQuery(log_path)
|
|
297
|
+
.by_pattern("COMPLETE.*")
|
|
298
|
+
.limit(1000)
|
|
299
|
+
.execute()
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
slow_count = 0
|
|
303
|
+
for op in slow_ops:
|
|
304
|
+
elapsed = op.get("context", {}).get("elapsed_ms", 0)
|
|
305
|
+
if elapsed > 100:
|
|
306
|
+
slow_count += 1
|
|
307
|
+
|
|
308
|
+
logger.debug(f"Found {slow_count} slow operations (>100ms)")
|
|
309
|
+
|
|
310
|
+
# Find by component
|
|
311
|
+
r1_logs = search_logs(log_path, component="R1", limit=100)
|
|
312
|
+
logger.debug(f"Found {len(r1_logs)} logs for R1")
|
|
313
|
+
|
|
314
|
+
logger.info("Log analysis complete")
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
"error_count": len(errors),
|
|
318
|
+
"slow_operations": slow_count,
|
|
319
|
+
"component_r1_logs": len(r1_logs),
|
|
320
|
+
"most_recent_error": errors[-1] if errors else None,
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
# ============================================================================
|
|
325
|
+
# EXAMPLE 7: Context Stacking
|
|
326
|
+
# ============================================================================
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def tool_complex_operation(schematic_uuid: str) -> Dict[str, Any]:
|
|
330
|
+
"""Example of nested context managers.
|
|
331
|
+
|
|
332
|
+
Example:
|
|
333
|
+
result = tool_complex_operation("abc123")
|
|
334
|
+
# Logs nested contexts with timing
|
|
335
|
+
"""
|
|
336
|
+
|
|
337
|
+
with operation_context("complex_operation"):
|
|
338
|
+
logger.info("Starting complex operation")
|
|
339
|
+
|
|
340
|
+
# Sub-step 1: Load
|
|
341
|
+
with operation_context("load_data"):
|
|
342
|
+
logger.debug("Loading schematic data")
|
|
343
|
+
# Simulate load
|
|
344
|
+
|
|
345
|
+
# Sub-step 2: Process components
|
|
346
|
+
with operation_context("process_components"):
|
|
347
|
+
logger.debug("Processing 10 components")
|
|
348
|
+
|
|
349
|
+
for i in range(3): # Simulate 3 components
|
|
350
|
+
ref = f"C{i+1}"
|
|
351
|
+
with ComponentLogger(ref) as comp_logger:
|
|
352
|
+
comp_logger.debug("Processing")
|
|
353
|
+
# Simulate processing
|
|
354
|
+
comp_logger.info("Processed")
|
|
355
|
+
|
|
356
|
+
# Sub-step 3: Validate
|
|
357
|
+
with operation_context("validate"):
|
|
358
|
+
logger.debug("Validating circuit")
|
|
359
|
+
# Simulate validation
|
|
360
|
+
|
|
361
|
+
logger.info("Complex operation complete")
|
|
362
|
+
|
|
363
|
+
return {"success": True}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
# ============================================================================
|
|
367
|
+
# EXAMPLE 8: Batch Operations with Logging
|
|
368
|
+
# ============================================================================
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def tool_batch_update_components(
|
|
372
|
+
schematic_uuid: str,
|
|
373
|
+
updates: Dict[str, Dict[str, Any]],
|
|
374
|
+
) -> Dict[str, Any]:
|
|
375
|
+
"""Update multiple components with logging.
|
|
376
|
+
|
|
377
|
+
Example:
|
|
378
|
+
result = tool_batch_update_components("abc123", {
|
|
379
|
+
"R1": {"value": "10k", "tolerance": "1%"},
|
|
380
|
+
"R2": {"value": "20k", "tolerance": "1%"},
|
|
381
|
+
})
|
|
382
|
+
"""
|
|
383
|
+
|
|
384
|
+
with operation_context("batch_update", details={"count": len(updates)}):
|
|
385
|
+
logger.info(f"Updating {len(updates)} components")
|
|
386
|
+
|
|
387
|
+
results = {}
|
|
388
|
+
|
|
389
|
+
for comp_ref, changes in updates.items():
|
|
390
|
+
with ComponentLogger(comp_ref) as comp_logger:
|
|
391
|
+
comp_logger.debug(f"Applying updates: {changes}")
|
|
392
|
+
|
|
393
|
+
try:
|
|
394
|
+
# Simulate update
|
|
395
|
+
updated = {
|
|
396
|
+
"reference": comp_ref,
|
|
397
|
+
**changes,
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
comp_logger.info("Updates applied successfully")
|
|
401
|
+
results[comp_ref] = updated
|
|
402
|
+
|
|
403
|
+
except Exception as e:
|
|
404
|
+
comp_logger.error(f"Update failed: {e}")
|
|
405
|
+
results[comp_ref] = {"error": str(e)}
|
|
406
|
+
|
|
407
|
+
logger.info(f"Batch update complete: {len(results)} components")
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
"success": True,
|
|
411
|
+
"results": results,
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
# ============================================================================
|
|
416
|
+
# MAIN EXAMPLE EXECUTION
|
|
417
|
+
# ============================================================================
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def run_examples():
|
|
421
|
+
"""Run all examples to demonstrate logging."""
|
|
422
|
+
|
|
423
|
+
print("\n" + "=" * 70)
|
|
424
|
+
print("MCP Server Logging Framework Examples")
|
|
425
|
+
print("=" * 70 + "\n")
|
|
426
|
+
|
|
427
|
+
# Setup logging
|
|
428
|
+
setup_server()
|
|
429
|
+
logger = get_mcp_logger()
|
|
430
|
+
|
|
431
|
+
# Example 1: Create schematic
|
|
432
|
+
print("\n1. Creating schematic...")
|
|
433
|
+
result = tool_create_schematic("MyCircuit")
|
|
434
|
+
print(f" Result: {result['success']}")
|
|
435
|
+
|
|
436
|
+
# Example 2: Add component
|
|
437
|
+
print("\n2. Adding resistor R1...")
|
|
438
|
+
result = tool_add_resistor(
|
|
439
|
+
"abc123",
|
|
440
|
+
"R1",
|
|
441
|
+
"10k",
|
|
442
|
+
"1%",
|
|
443
|
+
)
|
|
444
|
+
print(f" Result: {result['success']}")
|
|
445
|
+
print(f" Summary: {result['summary']}")
|
|
446
|
+
|
|
447
|
+
# Example 3: Build circuit
|
|
448
|
+
print("\n3. Building circuit with multiple components...")
|
|
449
|
+
result = tool_build_circuit(
|
|
450
|
+
"abc123",
|
|
451
|
+
{
|
|
452
|
+
"components": [
|
|
453
|
+
{"ref": "R1", "value": "10k"},
|
|
454
|
+
{"ref": "R2", "value": "20k"},
|
|
455
|
+
{"ref": "C1", "value": "100uF"},
|
|
456
|
+
],
|
|
457
|
+
},
|
|
458
|
+
)
|
|
459
|
+
print(f" Result: {result['success']}")
|
|
460
|
+
print(f" Components added: {result['components_added']}")
|
|
461
|
+
|
|
462
|
+
# Example 4: Get pin position (success)
|
|
463
|
+
print("\n4. Getting pin position...")
|
|
464
|
+
result = tool_get_pin_position("abc123", "R1", 1)
|
|
465
|
+
print(f" Result: {result['success']}")
|
|
466
|
+
print(f" Position: {result['position']}")
|
|
467
|
+
|
|
468
|
+
# Example 5: Analyze circuit
|
|
469
|
+
print("\n5. Analyzing circuit...")
|
|
470
|
+
result = tool_analyze_circuit("abc123")
|
|
471
|
+
print(f" Result: {result['success']}")
|
|
472
|
+
print(f" Components: {result['analysis']['component_count']}")
|
|
473
|
+
|
|
474
|
+
# Example 6: Complex operation
|
|
475
|
+
print("\n6. Running complex operation...")
|
|
476
|
+
result = tool_complex_operation("abc123")
|
|
477
|
+
print(f" Result: {result['success']}")
|
|
478
|
+
|
|
479
|
+
# Example 7: Batch update
|
|
480
|
+
print("\n7. Batch updating components...")
|
|
481
|
+
result = tool_batch_update_components(
|
|
482
|
+
"abc123",
|
|
483
|
+
{
|
|
484
|
+
"R1": {"value": "15k", "tolerance": "1%"},
|
|
485
|
+
"R2": {"value": "25k", "tolerance": "1%"},
|
|
486
|
+
},
|
|
487
|
+
)
|
|
488
|
+
print(f" Result: {result['success']}")
|
|
489
|
+
print(f" Updated: {len(result['results'])} components")
|
|
490
|
+
|
|
491
|
+
# Example 8: Analyze logs
|
|
492
|
+
print("\n8. Analyzing logs...")
|
|
493
|
+
result = analyze_logs()
|
|
494
|
+
print(f" Errors: {result['error_count']}")
|
|
495
|
+
print(f" Slow operations: {result['slow_operations']}")
|
|
496
|
+
print(f" R1 logs: {result['component_r1_logs']}")
|
|
497
|
+
|
|
498
|
+
# Summary
|
|
499
|
+
print("\n" + "=" * 70)
|
|
500
|
+
print("Example execution complete!")
|
|
501
|
+
print("Check logs/mcp_server.log for detailed operation logs")
|
|
502
|
+
print("=" * 70 + "\n")
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
if __name__ == "__main__":
|
|
506
|
+
run_examples()
|