Demo MCP client usage
()
| 187 | |
| 188 | |
| 189 | def main(): |
| 190 | """Demo MCP client usage""" |
| 191 | client = MCPClient() |
| 192 | |
| 193 | try: |
| 194 | # Connect and initialize |
| 195 | client.connect() |
| 196 | client.initialize() |
| 197 | |
| 198 | # List available tools |
| 199 | tools = client.list_tools() |
| 200 | |
| 201 | # List available resources |
| 202 | resources = client.list_resources() |
| 203 | |
| 204 | # Read current frame resource |
| 205 | if resources: |
| 206 | current_frame = client.read_resource("serialstudio://frame/current") |
| 207 | if current_frame: |
| 208 | for content in current_frame: |
| 209 | print(f"\n{content.get('text', 'No data')}") |
| 210 | |
| 211 | # Example: Calling api.getCommands tool |
| 212 | print("\n" + "=" * 60) |
| 213 | print("Example: Calling api.getCommands tool") |
| 214 | print("=" * 60) |
| 215 | result = client.call_tool("api.getCommands") |
| 216 | if result: |
| 217 | print(json.dumps(result, indent=2)) |
| 218 | |
| 219 | # Example: Get IO manager status |
| 220 | print("\n" + "=" * 60) |
| 221 | print("Example: Calling io.getStatus tool") |
| 222 | print("=" * 60) |
| 223 | result = client.call_tool("io.getStatus") |
| 224 | if result: |
| 225 | print(json.dumps(result, indent=2)) |
| 226 | |
| 227 | except KeyboardInterrupt: |
| 228 | print("\n\nInterrupted by user") |
| 229 | except Exception as e: |
| 230 | print(f"\n✗ Error: {e}") |
| 231 | import traceback |
| 232 | |
| 233 | traceback.print_exc() |
| 234 | finally: |
| 235 | client.close() |
| 236 | |
| 237 | |
| 238 | if __name__ == "__main__": |
no test coverage detected