Skip to main content
Glama

get_portfolio_analysis

Analyze investment portfolios to assess position values, allocation percentages, PnL, concentration risk, regime alignment, and generate rebalancing suggestions based on current market conditions.

Instructions

Get personalized portfolio analysis against current market conditions. Shows position values, allocation percentages, PnL, concentration risk, regime alignment, and specific rebalancing suggestions. Requires set_portfolio_context to be called first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function `getPortfolioAnalysis` fetches the user's portfolio, performs a market reality check, and uses the `analyzePortfolio` service to generate the analysis.
    export async function getPortfolioAnalysis(cache: CacheService): Promise<PortfolioAnalysisOutput | ErrorOutput> {
      const portfolio = getPortfolio(AGENT_ID);
    
      if (!portfolio || portfolio.holdings.length === 0) {
        return {
          error: true,
          error_source: 'get_portfolio_analysis',
          agent_guidance: 'No portfolio context found. Call set_portfolio_context first with your holdings array: [{asset: "bitcoin", amount: 2}, {asset: "solana", amount: 50}].',
          last_known_data: null,
          data_warnings: ['No portfolio context set for this agent.'],
        };
      }
    
      try {
        // Get current market reality
        const reality = await getRealityCheck(cache);
    
        // Extract regime info (handle both success and error cases)
        let posture = 'moderate';
        let regime = 'transitional';
        let riskScore = 50;
        let opportunityScore = 50;
    
        if ('suggested_posture' in reality) {
          const r = reality as RealityCheckOutput;
          posture = r.suggested_posture;
          regime = typeof r.regime === 'object' && r.regime !== null ? (r.regime as unknown as Record<string, string>).regime ?? 'transitional' : 'transitional';
          riskScore = r.risk_score;
          opportunityScore = r.opportunity_score;
        }
    
        const analysis = await analyzePortfolio(
          portfolio.holdings,
          posture,
          regime,
          riskScore,
        );
    
        return {
          ...analysis,
          market_context: {
            regime,
            posture,
            risk_score: riskScore,
            opportunity_score: opportunityScore,
          },
        };
      } catch {
        return {
          error: true,
          error_source: 'get_portfolio_analysis',
          agent_guidance: 'Portfolio analysis temporarily unavailable. Market data sources may be down. Retry shortly.',
          last_known_data: null,
          data_warnings: ['Portfolio analysis service temporarily unavailable.'],
        };
      }
    }
  • Interface definition for the output of `get_portfolio_analysis`.
    export interface PortfolioAnalysisOutput extends PortfolioAnalysis {
      market_context: {
        regime: string;
        posture: string;
        risk_score: number;
        opportunity_score: number;
      };
    }
  • src/index.ts:231-240 (registration)
    Registration and invocation logic for `get_portfolio_analysis` in the main entry point.
    // ─── Tool: get_portfolio_analysis ───
    server.tool(
      'get_portfolio_analysis',
      'Get personalized portfolio analysis against current market conditions. Shows position values, allocation percentages, PnL, concentration risk, regime alignment, and specific rebalancing suggestions. Requires set_portfolio_context to be called first.',
      {},
      async () => {
        const gateError = gateTool('get_portfolio_analysis');
        if (gateError) return { content: [{ type: 'text' as const, text: gateError }] };
    
        const text = await executeAndLog('get_portfolio_analysis', {}, () => getPortfolioAnalysis(cache));
Behavior3/5

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

Without annotations, the description carries the full burden of behavioral disclosure. It adequately reveals the stateful dependency on set_portfolio_context but fails to disclose other behavioral traits like idempotency, error responses when context is missing, caching behavior, or rate limits. The mention of what it 'Shows' implies read-only behavior but does not explicitly confirm no side effects.

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?

Three sentences with zero waste: sentence 1 defines purpose, sentence 2 enumerates outputs, and sentence 3 states prerequisites. Information is front-loaded and each sentence earns its place without redundant phrasing.

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

Completeness4/5

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

Given the lack of output schema, the description compensates by listing expected return components (position values, allocation percentages, PnL, etc.). It appropriately covers the stateful prerequisite for a zero-parameter tool, though annotations for read-only safety or performance hints would improve completeness.

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

Parameters4/5

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

The input schema contains zero parameters, establishing a baseline score of 4 per evaluation rules. The description implicitly explains the absence of personalization parameters by noting the requirement for set_portfolio_context, suggesting configuration happens externally rather than per-call.

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

Purpose4/5

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

The description states a clear action ('Get personalized portfolio analysis') and enumerates specific outputs including 'position values, allocation percentages, PnL, concentration risk, regime alignment, and specific rebalancing suggestions,' which distinguishes it from sibling tools like get_market_regime or get_account_status that return narrower datasets. However, 'personalized' remains vague regarding which entity's portfolio is analyzed.

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

Usage Guidelines4/5

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

Explicitly states the temporal prerequisite 'Requires set_portfolio_context to be called first,' establishing clear sequencing for when to use the tool. This prevents invocation errors by indicating the required setup state, though it does not explicitly list alternative tools for users without portfolio context.

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/0xHashy/fathom-fyi'

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