Financial-Modeling-Prep-MCP-Server
Copilot instructions149 starsChanged 5 months agoApache-2.0View on GitHub
This is a Model Context Protocol (MCP) server that exposes 253+ financial tools across 24 categories using the Financial Modeling Prep API. The codebase uses a stateful server architecture powered by the Smithery SDK with three operational modes:
- Reads credentials
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- code-reviewSkill
The file
We split this copilot-instructions.md into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 55
All tools follow this exact pattern in src/tools/*.ts:
- Very specific: line 77
All API clients in src/api/*/ extend FMPClient base class:
- Very specific: line 120
Test the DynamicToolsetManager enable/disable flow, especially module loading timeouts and validation.
- Distinctive: line 123
Verify clients properly extract API keys from session context vs constructor parameters.
- Distinctive: line 135
When adding new tools or modifying architecture, follow the established patterns for consistency and maintainability.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions 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
AI Coding Agent Instructions for Financial Modeling Prep MCP Server
Architecture Overview
This is a Model Context Protocol (MCP) server that exposes 253+ financial tools across 24 categories using the Financial Modeling Prep API. The codebase uses a stateful server architecture powered by the Smithery SDK with three operational modes:
- Dynamic Mode: Starts with 3 meta-tools, loads toolsets on-demand via
enable_toolset()calls - Static Mode: Pre-loads specific toolsets at startup via
FMP_TOOL_SETSenvironment variable or CLI arg - Legacy Mode: Loads all 253 tools at startup (default)
Key Components & Data Flow
Core Architecture Pattern
HTTP Request → FmpMcpServer → ClientStorage (by clientId) → McpServerFactory → DynamicToolsetManager → Individual Tool ModulesFmpMcpServer(src/server/FmpMcpServer.ts): Main HTTP server using Smithery SDK's stateful server wrapperClientStorage(src/client-storage/ClientStorage.ts): LRU storage with TTL keyed by clientId (derived from access token)McpServerFactory(src/mcp-server-factory/McpServerFactory.ts): Creates MCP server instances per sessionDynamicToolsetManager(src/dynamic-toolset-manager/DynamicToolsetManager.ts): Runtime tool loading/unloadingServerModeEnforcer(src/server-mode-enforcer/ServerModeEnforcer.ts): Handles config precedence and mode validation- Tool modules (
src/tools/*.ts): Individual tool registration functions following consistent patterns
Client Isolation Pattern
Exactly one McpServer instance and DynamicToolsetManager is maintained per clientId, where clientId = client:<sha256(token)>. If no token is provided, a per-request anon:<uuid> is used (no reuse). The SDK manages sessionId, but caching does not use it.
Development Workflows
Testing Strategy
- Framework: Vitest with comprehensive mocking patterns
- Key Pattern: Mock external dependencies in test files using
vi.mock()at module level - Run Tests:
npm test(watch mode) ornpm run test:run(single run) - Coverage:
npm run test:coverage
Mock Pattern Example (from FmpMcpServer.test.ts):
vi.mock("../client-storage/index.js", () => ({
ClientStorage: vi.fn().mockImplementation((options = {}) => ({
get: vi.fn(),
set: vi.fn(),
stop: vi.fn(), // Critical: mock ALL methods used in production
})),
}));Build & Development
- Build:
npm run build(TypeScript compilation todist/) - Dev Mode:
npm run dev(usestsx watch) - Entry Point:
src/index.ts→ CLI interface with minimist argument parsing
Project-Specific Conventions
Tool Registration Pattern
All tools follow this exact pattern in src/tools/*.ts:
export function registerXxxTools(server: McpServer, accessToken?: string): void {
const client = new XxxClient(accessToken);
server.tool("toolName", "description", {
param: z.string().describe("param description"),
}, async ({ param }) => {
try {
const results = await client.method(param);
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
} catch (error) {
return {
content: [{ type: "text", text: `Error: ${error.message}` }],
isError: true,
};
}
});
}API Client Pattern
All API clients in src/api/*/ extend FMPClient base class:
- Context-based API keys: Clients accept
contextparameter with session-specific tokens - Error handling: Consistent axios error wrapping with FMP-specific messages
- Method naming: Direct mapping to FMP API endpoints (e.g.,
getProfile,getQuote)
Environment Configuration Precedence
Server follows strict configuration hierarchy:
- Command line arguments (
--fmp-token,--dynamic-tool-discovery,--fmp-tool-sets,--port) - Environment variables (
FMP_ACCESS_TOKEN,DYNAMIC_TOOL_DISCOVERY,FMP_TOOL_SETS,PORT) - Session configuration (via HTTP query parameters - only when no server-level config)
Critical: Server-level configurations (CLI args or env vars) override ALL session configurations globally.
Capabilities Prompt and Authentication Requirement
- The server registers a human-friendly capabilities prompt
list_mcp_assetsthat summarizes modes, tools, resources, and quick-start. - The prompt now explicitly documents authentication behavior:
FMP_ACCESS_TOKENis optional for server initialization.- It is required to successfully call any FMP-backed tools; without a token, those calls will error.
- Token can be provided via CLI args/env vars or per-session config, with server-level values taking precedence.
Critical Integration Points
Smithery SDK Integration
- Uses
@smithery/sdk/server/stateful.jsfor session management createStatefulServer()wraps the core session resource function- Compatible with
CreateServerArg<SessionConfig>interface
Tool Set System
- Tool sets defined in:
src/constants/toolSets.tswith structured metadata - Module mapping: Both static (
src/tools/index.ts) and dynamic (DynamicToolsetManager.ts) registrations - Validation:
src/utils/validation.tshandles tool set parsing and sanitization
Error Handling Patterns
- Session errors: Logged but re-thrown to let Smithery SDK handle responses
- Tool errors: Caught and returned as
{ content: [...], isError: true } - API errors: Wrapped with context-specific error messages
Testing Critical Areas
Client Storage Testing
Mock ClientStorage with proper stop() method to avoid "not a function" errors in lifecycle tests.
Dynamic Tool Loading
Test the DynamicToolsetManager enable/disable flow, especially module loading timeouts and validation.
API Client Context Handling
Verify clients properly extract API keys from session context vs constructor parameters.
Key Files to Understand
src/server/FmpMcpServer.ts: Main server lifecycle and Smithery SDK integrationsrc/mcp-server-factory/McpServerFactory.ts: Mode resolution and server creation logicsrc/server-mode-enforcer/ServerModeEnforcer.ts: Configuration precedence and validationsrc/constants/toolSets.ts: Complete tool organization structuresrc/tools/index.ts: Static tool registration patternssrc/dynamic-toolset-manager/DynamicToolsetManager.ts: Runtime tool managementsrc/index.ts: CLI entry point with minimist argument parsing
When adding new tools or modifying architecture, follow the established patterns for consistency and maintainability.
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.

