Skip to main content
Glama
juanqui

joulescope-mcp

by juanqui

Query topic

query_topic
Read-only

Query a JouleScope driver topic to retrieve data. Provide a relative topic such as c/fw/version or an absolute device topic.

Instructions

Query a JouleScope driver topic. Provide a relative topic such as c/fw/version or an absolute device topic.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicYes
device_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler logic for query_topic. Uses the driver session to select a device, constructs the full topic, performs driver.query(), and returns device_path, full topic, and JSON-serializable value.
    def query_topic(self, topic: str, device_path: str | None = None) -> dict[str, Any]:
        with self._driver_session() as driver:
            device = self._select_device(driver, device_path=device_path, require_js220=False)
            full_topic = self._full_topic(device, topic)
            driver.open(device, mode="restore")
            try:
                value = driver.query(full_topic)
            finally:
                driver.close(device)
        return {"device_path": device, "topic": full_topic, "value": _jsonable(value)}
  • MCP tool registration using @mcp.tool decorator with title 'Query topic', description, read_only annotations, and structured_output=True. Delegates to service.query_topic().
    @mcp.tool(
        title="Query topic",
        description="Query a JouleScope driver topic. Provide a relative topic such as c/fw/version or an absolute device topic.",
        annotations=read_only,
        structured_output=True,
    )
    def query_topic(topic: str, device_path: str | None = None) -> dict[str, Any]:
        try:
            return service.query_topic(topic=topic, device_path=device_path)
        except JoulescopeMcpError as exc:
            raise _tool_error(exc) from exc
  • Helper function _full_topic that resolves a relative topic (e.g., 'c/fw/version') to an absolute device topic (e.g., 'u/js220/005920/c/fw/version').
    def _full_topic(self, device: str, topic: str) -> str:
        topic = topic.strip()
        if not topic:
            raise JoulescopeMcpError("topic must not be empty")
        if topic.startswith(device + "/"):
            return topic
        if (
            topic.startswith(("u/", "s/", "c/", "h/"))
            and not topic.startswith(device)
            and topic.startswith(("u/js", "s/js"))
        ):
            return topic
        return f"{device}/{topic.lstrip('/')}"
  • Helper function _jsonable that converts driver/numpy values to JSON-serializable types, used to format the query_topic return value.
    def _jsonable(value: Any) -> Any:
        """Convert common driver/numpy values into JSON-serializable values."""
    
        if hasattr(value, "item"):
            return value.item()
        if isinstance(value, dict):
            return {str(k): _jsonable(v) for k, v in value.items()}
        if isinstance(value, (list, tuple)):
            return [_jsonable(v) for v in value]
        if isinstance(value, bytes):
            return value.hex()
        return value
  • Test confirming query_topic accepts relative topics and returns the correct full topic.
    def test_query_and_publish_topics_accept_relative_topics() -> None:
        driver = FakeDriver()
        svc = service_with(driver)
        assert svc.query_topic("c/fw/version")["topic"] == "u/js220/005920/c/fw/version"
        assert svc.publish_topic("s/led/en", 0)["topic"] == "u/js220/005920/s/led/en"
        assert ("u/js220/005920/s/led/en", 0) in driver.published
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint and destructiveHint. Description adds no extra behavioral details beyond 'query', which is consistent. No contradiction.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences, front-loaded with action, no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Sufficient for a simple read query with good annotations and output schema. Could enhance by explaining when to provide device_path, but not essential.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Description adds meaning for 'topic' (relative/absolute device topic) beyond schema, but does not describe 'device_path' parameter. Schema coverage is 0%, so description partially compensates but is incomplete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states it queries a JouleScope driver topic, with examples of relative and absolute topics. Distinguishes from sibling tools like list_topics (lists) and publish_topic (writes).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage via topic type examples but lacks explicit guidance on when to use this tool versus siblings or when to choose relative vs absolute. No when-not criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/juanqui/joulescope-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server