Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/quickstart/mcp-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<p>
<strong>Server Time:</strong> <code id="server-time">Loading...</code>
</p>
<p>
<strong>Tool Meta Source:</strong> <code id="tool-meta-source">[none]</code>
</p>
<button id="get-time-btn">Get Server Time</button>
<script type="module" src="/src/mcp-app.ts"></script>
</body>
Expand Down
9 changes: 8 additions & 1 deletion examples/quickstart/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export function createServer(): McpServer {
},
async () => {
const time = new Date().toISOString();
return { content: [{ type: "text", text: time }] };
return {
content: [{ type: "text", text: time }],
_meta: {
timestamp: time,
source: "quickstart-server",
debugToken: "quickstart-meta-debug",
},
Comment on lines +40 to +44
};
},
);

Expand Down
10 changes: 10 additions & 0 deletions examples/quickstart/src/mcp-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ import { App } from "@modelcontextprotocol/ext-apps";

// Get element references
const serverTimeEl = document.getElementById("server-time")!;
const toolMetaSourceEl = document.getElementById("tool-meta-source")!;
const getTimeBtn = document.getElementById("get-time-btn")!;

// Create app instance
const app = new App({ name: "Get Time App", version: "1.0.0" });

function extractMetaSource(result: unknown): string {
const meta = (result as { _meta?: { source?: unknown } })._meta;
return typeof meta?.source === "string" ? meta.source : "[missing]";
}
Comment on lines +11 to +14

// Handle tool results from the server. Set before `app.connect()` to avoid
// missing the initial tool result.
app.ontoolresult = (result) => {
console.info("tool-result _meta:", (result as { _meta?: unknown })._meta);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.logs

const time = result.content?.find((c) => c.type === "text")?.text;
serverTimeEl.textContent = time ?? "[ERROR]";
toolMetaSourceEl.textContent = extractMetaSource(result);
};
Comment on lines 18 to 23

// Wire up button click
getTimeBtn.addEventListener("click", async () => {
// `app.callServerTool()` lets the UI request fresh data from the server
const result = await app.callServerTool({ name: "get-time", arguments: {} });
console.info("callServerTool _meta:", (result as { _meta?: unknown })._meta);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.logs

const time = result.content?.find((c) => c.type === "text")?.text;
serverTimeEl.textContent = time ?? "[ERROR]";
toolMetaSourceEl.textContent = extractMetaSource(result);
Comment on lines 28 to +32
});

// Connect to host
Expand Down