Skip to main content
Glama
maven81g

TradeStation MCP Server

by maven81g

marketData

Retrieve real-time market quotes for trading symbols to access current price data through TradeStation's API.

Instructions

Get quotes for symbols

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolsYesComma-separated list of symbols

Implementation Reference

  • Zod input schema for the marketData tool, defining the 'symbols' parameter as a comma-separated string of trading symbols.
    const marketDataSchema = {
      symbols: z.string().describe('Comma-separated list of symbols')
    };
  • Full handler implementation for the 'marketData' tool: registers the tool with MCP server, parses 'symbols' argument, calls TradeStation /marketdata/quotes/{symbols} endpoint via authenticated request, returns JSON-formatted quotes or error message.
    server.tool(
      "marketData",
      "Get quotes for symbols",
      marketDataSchema,
      async (args) => {
        try {
          const { symbols } = args;
    
          // Fixed: symbols should be in the path, not query parameter
          const quotes = await makeAuthenticatedRequest(
            `/marketdata/quotes/${encodeURIComponent(symbols)}`
          );
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(quotes, null, 2)
              }
            ]
          };
        } catch (error: unknown) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to fetch market data: ${error instanceof Error ? error.message : 'Unknown error'}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Core helper function used by marketData handler for making authenticated HTTP requests to TradeStation API, including automatic token refresh and comprehensive error handling.
    async function makeAuthenticatedRequest(
      endpoint: string,
      method: AxiosRequestConfig['method'] = 'GET',
      data: any = null
    ): Promise<any> {
      const userTokens = tokenStore.get(DEFAULT_USER);
    
      if (!userTokens) {
        throw new Error('User not authenticated. Please set TRADESTATION_REFRESH_TOKEN in .env file.');
      }
    
      // Check if token is expired or about to expire (within 60 seconds)
      if (userTokens.expiresAt < Date.now() + 60000) {
        // Refresh the token
        const newTokens = await refreshToken(userTokens.refreshToken);
        tokenStore.set(DEFAULT_USER, newTokens);
      }
    
      try {
        const options: AxiosRequestConfig = {
          method,
          url: `${TS_API_BASE}${endpoint}`,
          headers: {
            'Authorization': `Bearer ${tokenStore.get(DEFAULT_USER)?.accessToken}`,
            'Content-Type': 'application/json',
            'Accept': 'application/json'
          },
          timeout: 60000
        };
    
        if (data && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
          options.data = data;
        }
    
        const response = await axios(options);
        return response.data;
      } catch (error: unknown) {
        if (error instanceof AxiosError) {
          const errorMessage = error.response?.data?.Message || error.response?.data?.message || error.message;
          const statusCode = error.response?.status;
          console.error(`API request error [${statusCode}]: ${errorMessage}`);
          console.error('Endpoint:', endpoint);
          throw new Error(`API Error (${statusCode}): ${errorMessage}`);
        } else if (error instanceof Error) {
          console.error('API request error:', error.message);
          throw error;
        } else {
          console.error('Unknown API request error:', error);
          throw new Error('Unknown API request error');
        }
      }
    }
  • Helper function for refreshing OAuth access tokens, called by makeAuthenticatedRequest when token is expired.
    async function refreshToken(refreshToken: string): Promise<TokenData> {
      try {
        const response = await axios.post<RefreshTokenResponse>(TS_TOKEN_URL,
          new URLSearchParams({
            grant_type: 'refresh_token',
            client_id: TS_CLIENT_ID!,
            client_secret: TS_CLIENT_SECRET!,
            refresh_token: refreshToken
          }), 
          {
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
          }
        );
        
        return {
          accessToken: response.data.access_token,
          refreshToken: refreshToken,
          expiresAt: Date.now() + 3600000 // 1 hour from now
        };
      } catch (error: unknown) {
        if (error instanceof AxiosError) {
          console.error('Error refreshing token:', error.response?.data || error.message);
        } else if (error instanceof Error) {
          console.error('Error refreshing token:', error.message);
        } else {
          console.error('Unknown error refreshing token:', error);
        }
        throw new Error('Failed to refresh token');
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Get quotes for symbols' implies a read-only operation, but it doesn't specify any behavioral traits like rate limits, authentication needs, data freshness, or potential costs. The description is minimal and fails to provide necessary context for safe and effective use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just four words, front-loaded and to the point. There is no wasted language or unnecessary elaboration, making it efficient for quick understanding. Every word contributes directly to stating the tool's purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete for effective use. It doesn't cover behavioral aspects like data sources, latency, or error handling, and with no output schema, it fails to hint at return values. For a tool that likely involves external data fetching, this leaves significant gaps in understanding its operation and results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'symbols' parameter documented as a 'Comma-separated list of symbols'. The description adds no additional meaning beyond this, as it doesn't explain format examples, symbol types, or constraints. Given the high schema coverage, a baseline score of 3 is appropriate, as the schema handles the parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get quotes for symbols' clearly states the verb ('Get') and resource ('quotes for symbols'), making the purpose understandable. However, it lacks specificity about what type of quotes (e.g., real-time, delayed, market data) and doesn't differentiate from sibling tools like 'getSymbolDetails' or 'searchSymbols', which might provide related information. It avoids tautology but remains somewhat vague.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any context, prerequisites, or exclusions, such as whether it's for real-time data, historical data, or how it differs from siblings like 'getSymbolDetails' or 'searchSymbols'. This leaves the agent without clear direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maven81g/tradestation_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server