> ## Documentation Index
> Fetch the complete documentation index at: https://docs.meshagent.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Room toolkits

> Deploy a Python toolkit and test its REST data clients with the MeshAgent CLI.

A room toolkit publishes named tools through a `Service` spec. Each Python tool runs in Monty and receives a JSON object. Set `metadata.name` to choose the public toolkit name, and put each function under `toolkit.tools` with `type: python`, an input schema, and its Python source. The function name matches the tool name unless you set `entrypoint`.

Room and project service deployments are available through the [Room Toolkits REST API](https://docs.meshagent.com/rest_api/room_toolkits.md). The HTTP endpoint can invoke a deployed toolkit while the room is stopped. Calls to Datasets and SQLite use room compute and may start the room. Files use persistent storage directly. See the [Datasets and SQLite REST API](https://docs.meshagent.com/rest_api/room_data.md) and the [Files REST API](https://docs.meshagent.com/rest_api/files.md).

## Use the room clients in a tool

Monty provides `meshagent.datasets`, `meshagent.sqlite`, and `meshagent.files`. Call `for_room(project_id=..., room_name=...)` with the invocation's room. The clients use the caller's grants for that room, and the executor handles the credentials. A denied client operation raises `PermissionError`. Use `toolkit.connections`, `toolkit.environment`, and `toolkit.run_as` for [configured HTTP requests and secrets](https://docs.meshagent.com/agents/tools/managed_python_tools.md).

Use `import pyarrow as pa` for Rust-backed Arrow tables, record batches, schemas, arrays, and scalars. Dataset and SQLite results can go directly into writes, and `async for` reads streamed results batch by batch. Convert Arrow objects to JSON-compatible values for the tool's final result. Files support streaming uploads and downloads. Whole-file `download()` and byte-buffer uploads have a 1 MiB limit in Monty.

`context.caller` identifies the authenticated caller. `context.on_behalf_of` identifies the verified delegated principal when supplied. Each principal has an `id`, a `type` of `user`, `service_account`, or `agent`, and optional `name` and `participant_id`. Either principal field can be `None`.

## Test with the CLI

Use a test room and sign in with a CLI identity that can deploy services, invoke tools, and create, read, and delete test data. Save this spec as `toolkit.yaml`. The probe queries SQLite, copies the Arrow table to a dataset, streams the dataset rows, and round-trips a small file. It uses the supplied run ID to isolate its data and cleans up the resources it creates.

```yaml Yaml theme={null}
version: v1
kind: Service
metadata:
  name: room-data-probe
  description: Verify room data access from a Monty toolkit
toolkit:
  tools:
    - type: python
      name: probe
      description: Round-trip a value through SQLite, Datasets, and Files
      input_schema:
        type: object
        properties:
          project_id:
            type: string
          room_name:
            type: string
          run_id:
            type: string
            pattern: "^[A-Za-z0-9_-]+$"
        required: [project_id, room_name, run_id]
        additionalProperties: false
      source: |
        import logging
        import pyarrow as pa

        async def probe(args):
            scope = {"project_id": args["project_id"], "room_name": args["room_name"]}
            run_id = args["run_id"]
            namespace = ["toolkit-probe", run_id]
            datasets = meshagent.datasets.for_room(**scope)
            sqlite = meshagent.sqlite.for_room(**scope)
            files = meshagent.files.for_room(**scope)
            database = sqlite.database("probe", namespace=namespace)

            await database.create_database()
            try:
                table = await database.sql(query="SELECT ? AS value", params=[42])
                assert isinstance(table, pa.Table)
                await datasets.create_table_from_data(
                    name="probe", data=table, namespace=namespace
                )
                try:
                    rows = []
                    stream = datasets.sql_stream(
                        query="SELECT value FROM probe", namespace=namespace
                    )
                    try:
                        async for batch in stream:
                            rows.extend(batch.to_pylist())
                    finally:
                        await stream.aclose()

                    path = "toolkit-probe-" + run_id + ".txt"
                    await files.upload(path, str(rows[0]["value"]).encode(), overwrite=False)
                    try:
                        value = (await files.download(path)).decode()
                    finally:
                        await files.delete(path)
                finally:
                    await datasets.drop_table(name="probe", namespace=namespace)
            finally:
                await database.drop_database()

            logging.getLogger("room-data-probe").info("Round-trip complete")
            return {"value": int(value), "rows": rows}

```

Set your project and test room, then validate and deploy the spec.

```bash theme={null}
PROJECT_ID="your-project-id"
ROOM_NAME="toolkit-test"

meshagent rooms create "$ROOM_NAME" --project-id "$PROJECT_ID" --if-not-exists
meshagent service validate --file toolkit.yaml
meshagent service create --file toolkit.yaml --project-id "$PROJECT_ID" --room "$ROOM_NAME"
```

Discover the tool and invoke it over HTTP. The CLI obtains the room credential from your signed-in session.

```bash theme={null}
meshagent room agents list-toolkits --project-id "$PROJECT_ID" --room "$ROOM_NAME" --http

RUN_ID="$(date +%s)"
ARGS="$(printf '{"project_id":"%s","room_name":"%s","run_id":"%s"}' "$PROJECT_ID" "$ROOM_NAME" "$RUN_ID")"

meshagent room agents invoke-tool --project-id "$PROJECT_ID" --room "$ROOM_NAME" \
  --toolkit room-data-probe --tool probe --arguments "$ARGS" --http
```

The tool should return `{"value":42,"rows":[{"value":42}]}`. For a Room Protocol test, repeat the invocation with a fresh run ID and omit `--http`. The CLI then joins the room and calls the registered toolkit.

To test a source change, get the deployment ID for `room-data-probe`, validate the revised spec, and update the service.

```bash theme={null}
meshagent service list --project-id "$PROJECT_ID" --room "$ROOM_NAME"
SERVICE_ID="your-service-deployment-id"
meshagent service validate --file toolkit.yaml
meshagent service update --id "$SERVICE_ID" --file toolkit.yaml \
  --project-id "$PROJECT_ID" --room "$ROOM_NAME"
```

## Inspect the test run

Use the service deployment ID from `meshagent service list` to inspect telemetry for either transport.

```bash theme={null}
meshagent service logs "$SERVICE_ID" --project-id "$PROJECT_ID" --room "$ROOM_NAME"
meshagent service traces "$SERVICE_ID" --project-id "$PROJECT_ID" --room "$ROOM_NAME" --attrs
meshagent service metrics "$SERVICE_ID" --project-id "$PROJECT_ID" --room "$ROOM_NAME"
```

The probe writes a `Round-trip complete` log. The trace contains a toolkit invocation span and child spans for the REST calls. For a permission failure, check the caller's tool and data grants. In Studio, open the toolkit service's options menu and choose **View Telemetry** to see the same signals. These commands use the service deployment ID without a session ID. See [Observability](https://docs.meshagent.com/observability/overview.md).

When finished, remove the test toolkit deployment.

```bash theme={null}
meshagent service delete "$SERVICE_ID" --project-id "$PROJECT_ID" --room "$ROOM_NAME"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.