From d4dbce15a04fd8754303767cd91262baace184e1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 24 Jul 2026 21:10:34 +0000 Subject: [PATCH] feat(cli/mcp): add slash command prompts and update docs - Register 'sessions' and 'spend' MCP prompts so clients like Claude Code surface /mcp__agentmeter__sessions and /mcp__agentmeter__spend as slash commands; both accept optional string args (limit / days) and embed live data directly into the prompt message for instant context - Add prompts:{} to server capabilities - README: add slash commands table, add Updating section covering npx @latest vs global install and the restart-after-update note --- packages/cli/README.md | 49 +++++++++++++++++++++++++++++ packages/cli/src/commands/mcp.ts | 54 +++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index 873e1e8..d9836d7 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -38,6 +38,15 @@ Add to your MCP client config and start asking questions. The server scans your The first call scans your local data (takes a moment). Subsequent calls within 60 seconds return instantly from the in-memory cache. +### Slash commands + +Once connected, these are available as slash commands in your AI agent: + +| Command | Description | +|---------|-------------| +| `/mcp__agentmeter__sessions` | Show recent sessions — token usage, duration, model. Optional: `limit` | +| `/mcp__agentmeter__spend` | Show spend summary and daily breakdown (requires account). Optional: `days` | + ### Available tools (no account needed) | Tool | Description | @@ -107,6 +116,46 @@ Example questions unlocked with an account: --- +## Updating + +**Using `npx` (default config):** npx caches the package. To always resolve the latest version, use `@latest` in your config args: + +```json +{ + "mcpServers": { + "agentmeter": { + "command": "npx", + "args": ["@agentmeter/cli@latest", "mcp"] + } + } +} +``` + +**Using a global install** (faster startup, explicit updates): + +```bash +npm install -g @agentmeter/cli +``` + +Then use `agentmeter` as the command directly: + +```json +{ + "mcpServers": { + "agentmeter": { + "command": "agentmeter", + "args": ["mcp"] + } + } +} +``` + +To update: `npm install -g @agentmeter/cli@latest` + +**After updating:** restart your MCP client (Claude Code, Cursor) — MCP servers are not hot-reloaded. + +--- + ## CLI reference The CLI is optional for MCP usage but required for background auto-sync and for submitting sessions to AgentMeter. diff --git a/packages/cli/src/commands/mcp.ts b/packages/cli/src/commands/mcp.ts index 680dc5a..518345a 100644 --- a/packages/cli/src/commands/mcp.ts +++ b/packages/cli/src/commands/mcp.ts @@ -395,7 +395,7 @@ export async function handleGetTeamSpend({ async function startMcpServer(): Promise { const server = new McpServer( { name: 'agentmeter', version: '1.0.0' }, - { capabilities: { tools: {} } }, + { capabilities: { prompts: {}, tools: {} } }, ); server.tool( @@ -465,6 +465,58 @@ async function startMcpServer(): Promise { async ({ days = 30 }) => handleGetTeamSpend({ days }), ); + // ------------------------------------------------------------------------- + // Prompts — surfaced as slash commands in MCP clients (e.g. /mcp__agentmeter__sessions) + // ------------------------------------------------------------------------- + + server.prompt( + 'sessions', + 'Show your recent AI coding sessions — token usage, duration, model, and repo', + { + limit: z.string().optional().describe('Number of sessions to show (1–50, default 10)'), + }, + async ({ limit }) => { + const limitNum = limit ? Math.min(50, Math.max(1, Number.parseInt(limit, 10) || 10)) : 10; + const result = await handleListRecentSessions({ limit: limitNum }); + const data = result.content[0]?.text ?? '{}'; + return { + messages: [ + { + role: 'user' as const, + content: { + type: 'text' as const, + text: `Here are my ${limitNum} most recent AI coding sessions:\n\n${data}\n\nPlease summarise what I have been working on, call out any sessions that used an unusually high number of tokens, and give me the total token count across all sessions shown.`, + }, + }, + ], + }; + }, + ); + + server.prompt( + 'spend', + 'Show your AI coding spend summary and daily breakdown (requires AgentMeter account)', + { + days: z.string().optional().describe('Number of days to look back (default 7)'), + }, + async ({ days }) => { + const daysNum = days ? Math.min(365, Math.max(1, Number.parseInt(days, 10) || 7)) : 7; + const result = await handleGetMySpend({ days: daysNum }); + const data = result.content[0]?.text ?? '{}'; + return { + messages: [ + { + role: 'user' as const, + content: { + type: 'text' as const, + text: `Here is my AI coding spend data for the last ${daysNum} day${daysNum === 1 ? '' : 's'}:\n\n${data}\n\nPlease summarise my spending trends, highlight any notable spikes or patterns, and give me a sense of whether my usage is tracking high or low.`, + }, + }, + ], + }; + }, + ); + const transport = new StdioServerTransport(); await server.connect(transport); }