MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / main

Function main

examples/MCP Client/client.py:189–235  ·  view source on GitHub ↗

Demo MCP client usage

()

Source from the content-addressed store, hash-verified

187
188
189def 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
238if __name__ == "__main__":

Callers 1

client.pyFile · 0.70

Calls 9

connectMethod · 0.95
initializeMethod · 0.95
list_toolsMethod · 0.95
list_resourcesMethod · 0.95
read_resourceMethod · 0.95
call_toolMethod · 0.95
closeMethod · 0.95
MCPClientClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected