Skip to main content
Glama

show_concentration

Calculate portfolio concentration using Herfindahl-Hirschman Index across ticker, currency, sector, and country dimensions. Identifies top contributors and flags high or very high concentration.

Instructions

Portfolio concentration measured by Herfindahl-Hirschman Index (HHI) across ticker, currency, sector, and country dimensions. HHI ranges 0–10000; >2500 is high, >5000 very high. Returns top contributors per dimension.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'show_concentration' - computes HHI concentration by ticker, currency, sector, and country dimensions. Gets transactions from DB, aggregates holdings, maps with prices, and returns grouped slices with HHI scores and top contributors.
    server.tool(
      'show_concentration',
      'Portfolio concentration measured by Herfindahl-Hirschman Index (HHI) across ticker, currency, sector, and country dimensions. HHI ranges 0–10000; >2500 is high, >5000 very high. Returns top contributors per dimension.',
      {},
      async () => {
        const db = getDb();
        const txns = db.select().from(transactions).all();
        const holdings = aggregateHoldings(txns);
        if (holdings.size === 0) return ok({});
    
        const priceMap = new Map(
          db
            .select()
            .from(prices)
            .all()
            .map((p) => [p.ticker, p]),
        );
    
        const positions = [...holdings.entries()]
          .map(([ticker, h]) => {
            const p = priceMap.get(ticker);
            const marketValue = p ? p.current_price * h.shares : 0;
            return {
              ticker,
              marketValue,
              currency: p?.currency ?? 'USD',
              sector: p?.sector ?? 'Unknown',
              country: p?.country ?? 'Unknown',
            };
          })
          .filter((p) => p.marketValue > 0);
    
        const hhi = (slices: { value: number }[]) => {
          const total = slices.reduce((s, x) => s + x.value, 0);
          if (total <= 0) return 0;
          return Math.round(
            slices.reduce((s, { value }) => {
              const p = value / total;
              return s + p * p * 10000;
            }, 0),
          );
        };
    
        const groupBy = (keyOf: (p: (typeof positions)[number]) => string) => {
          const map = positions.reduce(
            (m, p) => m.set(keyOf(p), (m.get(keyOf(p)) ?? 0) + p.marketValue),
            new Map<string, number>(),
          );
          const slices = [...map.entries()]
            .map(([label, value]) => ({ label, value }))
            .sort((a, b) => b.value - a.value);
          const total = slices.reduce((s, x) => s + x.value, 0);
          return {
            hhi: hhi(slices),
            slices: slices.map((s) => ({
              label: s.label,
              value: s.value,
              pct: total > 0 ? (s.value / total) * 100 : 0,
            })),
          };
        };
    
        return ok({
          by_ticker: groupBy((p) => p.ticker),
          by_currency: groupBy((p) => p.currency),
          by_sector: groupBy((p) => p.sector),
          by_country: groupBy((p) => p.country),
        });
      },
    );
  • Registration of the portfolio tools (including show_concentration) via registerPortfolioTools(server) at MCP server startup.
    registerPortfolioTools(server);
    registerReportTools(server);
    registerMutateTools(server);
    registerSnapshotTools(server);
    registerStockTools(server);
  • Export function registerPortfolioTools that registers show_concentration and other portfolio tools on the MCP server instance.
    export function registerPortfolioTools(server: McpServer): void {
  • Helper function aggregateHoldings - aggregates transaction records into a Map of ticker to Holding (shares, cost basis). Used by the show_concentration handler.
    export const aggregateHoldings = (txns: Transaction[]): Map<string, Holding> => {
      const sorted = [...txns].sort((a, b) => a.date.localeCompare(b.date));
    
      const map = sorted.reduce((acc, t) => {
        const h = acc.get(t.ticker) ?? { ticker: t.ticker, shares: 0, costShares: 0, totalCost: 0 };
    
        if (t.type === 'buy') {
          h.shares += t.shares;
          h.costShares += t.shares;
          h.totalCost += t.shares * t.price;
        } else if (t.type === 'sell') {
          const ratio = h.shares > 0 ? (h.shares - t.shares) / h.shares : 0;
          h.shares -= t.shares;
          h.costShares = h.costShares * ratio;
          h.totalCost = h.totalCost * ratio;
        } else if (t.type === 'deposit') {
          h.shares += t.shares;
          if (t.price > 0) {
            h.costShares += t.shares;
            h.totalCost += t.shares * t.price;
          }
        }
    
        return acc.set(t.ticker, h);
      }, new Map<string, Holding>());
    
      return new Map([...map.entries()].filter(([, h]) => h.shares > 0));
    };
  • Server instructions mentioning show_concentration as part of the risk/concentration/rebalance investigation protocol.
    - Risk / concentration / rebalance → get_brief + show_concentration.
    - Macro / market environment → get_brief (signals and macro are already inside).
Behavior3/5

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

With no annotations, the description carries the full burden. It explains the HHI range and that top contributors are returned, but does not disclose prerequisites (e.g., portfolio must exist) or the output format beyond contributors.

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?

Two sentences, no unnecessary words. Efficiently conveys purpose, metric, thresholds, and output dimensions.

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 no output schema and zero parameters, the description adequately explains what the tool returns (HHI and top contributors per dimension). It could be more specific about output format, but still provides essential information.

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?

There are zero parameters, so the baseline is 4. The description adds value by explaining the meaning of the output (HHI range and thresholds).

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

Purpose5/5

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

The description clearly states it measures portfolio concentration using HHI across multiple dimensions (ticker, currency, sector, country). It distinguishes from siblings like show_risk or show_balance by focusing specifically on concentration metrics.

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

Usage Guidelines3/5

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

Usage context is implied but not explicit. No when-to-use or when-not-to-use guidance is provided, and alternatives among the many siblings are not mentioned.

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/evan-moon/firma'

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