tableau-mcp / rules
Cursor rule347 starsChanged 6 months agoApache-2.0View on GitHub
MCP tool development patterns — factory pattern, base class, callbacks, and descriptions
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/auth.mdcCursor rule
- .cursor/rules/tableau-mcp.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- create-pr-from-commitsSkill
The file
We split this tools.mdc into the rules it gives an agent
7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Every tool exports a factory function registered in src/tools/tools.ts:
- Very specific: line 27
Add tool name to toolNames array in src/tools/toolName.ts
- Very specific: line 28
Add to appropriate toolGroups entry (or create new group)
- Very specific: line 29
Add scope mapping in src/server/oauth/scopes.ts (toolScopeMap)
- Very specific: line 30
Create tool directory under src/tools/
- Distinctive: line 85
Every MCP tool description must include:
- Very specific: line 95
Use constrainSuccessResult for business logic validation (empty results, etc.)
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: MCP tool development patterns — factory pattern, base class, callbacks, and descriptions
globs:
- "src/tools/**/*.ts"
---
# Tool Development Patterns
## Factory Pattern
Every tool exports a factory function registered in `src/tools/tools.ts`:
```typescript
export const getMyTool = (server: Server): Tool<typeof paramsSchema> => {
const myTool = new Tool({
server,
name: 'my-tool', // Must be in ToolName union (src/tools/toolName.ts)
description: '...',
paramsSchema, // Zod schema object (not z.object, just raw shape)
annotations: { title: 'My Tool', readOnlyHint: true, openWorldHint: false },
callback: async (args, extra) => { ... },
});
return myTool;
};
```
## Adding a New Tool — Checklist
1. Add tool name to `toolNames` array in `src/tools/toolName.ts`
2. Add to appropriate `toolGroups` entry (or create new group)
3. Add scope mapping in `src/server/oauth/scopes.ts` (`toolScopeMap`)
4. Create tool directory under `src/tools/`
5. Implement factory function following the pattern above
6. Register factory in `src/tools/tools.ts` (`toolFactories` array)
## Tool Callback Pattern
Callbacks use `logAndExecute` from the base `Tool` class:
```typescript
callback: async (args, extra): Promise<CallToolResult> => {
return await myTool.logAndExecute({
extra,
args,
callback: async () => {
const result = await useRestApi({
...extra,
jwtScopes: myTool.requiredApiScopes,
callback: async (restApi) => {
// Use restApi methods here
return data;
},
});
return new Ok(result); // ts-results-es Ok()
},
constrainSuccessResult: (result) => constrainMyResult(result),
});
},
```
## Result Types
- `Result<T, E>` from `ts-results-es` — tool callbacks return this
- `Ok(value)` for success, `Err(error)` for typed errors
- `ConstrainedResult<T>` — post-processing step with three outcomes:
- `{ type: 'success', result: T }` — data returned to client
- `{ type: 'empty', message: string }` — no data found (not an error)
- `{ type: 'error', message: string, error?: Error }` — logical error
## Tool Context (TableauRequestHandlerExtra)
Available in `extra` parameter:
- `config` — server configuration
- `server` — MCP Server instance
- `tableauAuthInfo` — auth info (may be undefined for unauthenticated)
- `getConfigWithOverrides()` — config with site and request overrides applied
- `getSiteLuid()` / `getUserLuid()` — resolved identifiers
- `setSiteLuid()` / `setUserLuid()` — set during auth lifecycle
- `requestId` — unique request identifier
- `signal` — AbortSignal for cancellation
## useRestApi() (src/restApiInstance.ts)
Single entry point for authenticated Tableau API calls:
- Creates fresh RestApi instance per call
- Handles auth lifecycle (sign-in, token setup, sign-out)
- Pass `jwtScopes: tool.requiredApiScopes` for scope-aware auth
- Pass `...extra` to forward auth info, config, signal, etc.
## Tool Description Standards
Every MCP tool description must include:
- What the tool does (primary purpose)
- Which Tableau API it uses
- What parameters it accepts and their formats
- What it returns on success
- Explicit boundary: when to use THIS tool vs similar tools
## Error Handling in Tools
- Let `logAndExecute` handle error wrapping via `getErrorResult()`
- Zod/Zodios validation errors → non-error result with warning + raw data
- Use `constrainSuccessResult` for business logic validation (empty results, etc.)
- HTTP status extracted automatically from AxiosError via `getHttpStatus()`
- Telemetry recorded automatically (success/failure, error_code, tool_name)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

