Add a second MCP tool and validate its output

Extend the meeting-notes server with a filterable list_notes tool and test the behavior of valid, absent, and invalid filters.

Define the operation and its boundary

A caller might know that it wants confirmed meeting notes without knowing their IDs. Keep get_note for exact lookup and add list_notes for selecting a subset. Its only optional input is status, which may be draft or confirmed. An empty argument object requests all records.

Return a JSON array with IDs, titles, and statuses. An empty array is a valid result if there are no matches. A request for an unsupported status should fail schema validation instead of quietly widening the query.

Register list_notes on the same server

In src/server.ts, insert this registration inside createServer before return server. It uses the same fixed notes map as get_note, so browsing and lookup cannot disagree over the sample records.

Code
server.registerTool(
  "list_notes",
  {
    description: "List sample meeting notes, optionally restricted to one status.",
    inputSchema: z.object({
      status: z.enum(["draft", "confirmed"]).optional(),
    }),
    annotations: { readOnlyHint: true },
  },
  async ({ status }) => {
    const rows = [...notes].flatMap(([id, note]) =>
      !status || note.status === status ? [{ id, ...note }] : [],
    );
    return { content: [{ type: "text", text: JSON.stringify(rows) }] };
  },
);

Extend the smoke test

Insert this block before console.log in src/smoke.ts, with the connected client and the existing assert import. Rebuild and run npm run smoke. If the draft note appears in the filtered result, examine the filter condition. If the call reports an unknown tool, check that the new registration is inside the factory and that the server was rebuilt.

Code
const selected = await client.callTool({
  name: "list_notes",
  arguments: { status: "confirmed" },
});
assert.notEqual(selected.isError, true);
const selectedBlock = selected.content.find((item) => item.type === "text");
assert.ok(selectedBlock && selectedBlock.type === "text");
assert.deepEqual(JSON.parse(selectedBlock.text), [
  { id: "weekly-01", title: "Weekly planning", status: "confirmed" },
]);

const all = await client.callTool({ name: "list_notes", arguments: {} });
const allBlock = all.content.find((item) => item.type === "text");
assert.ok(allBlock && allBlock.type === "text");
assert.equal(JSON.parse(allBlock.text).length, 2);

const badStatus = await client.callTool({
  name: "list_notes", arguments: { status: "unknown" },
});
assert.equal(badStatus.isError, true);

Decide when to add an output schema

These tools provide JSON as a text block for compatibility with the clients being compared. If your application needs typed fields, register an output schema and return structuredContent that matches it. Test the shape with the SDK client before changing the host integration. Keep the read-only restriction in the implementation. A discovery hint describes the behavior and does not enforce it.

MCP tool calls and structured output

Related reading

What Is MCP Server?

Your First MCP Server

Connect to Claude Desktop