Skip to main content
Glama
YusukeYajima

karte-datahub-mcp

by YusukeYajima

karte-datahub-mcp

KARTE のイベントデータを BigQuery 経由で安全にクエリするための MCP(Model Context Protocol)サーバーです。

Claude Code などの MCP 対応 AI アシスタントに KARTE イベントデータへのアクセス機能を提供します。

前提条件

  • Python 3.13 以上

  • uv パッケージマネージャー

  • GCP サービスアカウントの認証情報ファイル

  • KARTE API キー

Related MCP server: BigQuery MCP

セットアップ

1. 依存関係のインストール

cd karte-datahub-mcp
uv sync

2. 環境変数

環境変数

必須

説明

デフォルト

KARTE_API_KEY

Yes

KARTE API キー

-

CREDENTIAL_FILE

No

サービスアカウントキーファイルパス

-

BQ_PROJECT

No

BigQuery クエリ実行用 GCP プロジェクト

-

DATA_PROJECT

No

KARTE データプロジェクト

karte-data

3. Claude Code への登録

.mcp.json に以下を追加します。

{
  "mcpServers": {
    "karte-datahub-mcp": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/karte-datahub-mcp", "karte-mcp-server"],
      "env": {
        "KARTE_API_KEY": "<your-karte-api-key>",
        "CREDENTIAL_FILE": "/path/to/credential.json",
        "BQ_PROJECT": "<your-gcp-project>"
      }
    }
  }
}

注意

  • Pathは絶対パスである必要があります

  • 払い出しサービスアカウントを利用する場合は、「BQ_PROJECT」に以下を設定

    • prd-karte-service-account-2

提供ツール

MCP サーバーとして以下の 4 つのツールを公開します。

query_karte_events - イベントデータ取得

KARTE イベントテーブルからデータを取得します。

パラメータ

デフォルト

説明

select_columns

string

"*"

SELECT句(例: "event_name, user_id"

where_clause

string | null

null

WHERE条件(例: "event_name = 'click'"

date_from

string | null

2日前

開始日(YYYYMMDD形式)

date_to

string | null

昨日

終了日(YYYYMMDD形式)

limit

int | null

100

取得件数上限(1〜10000)。null で制限なし

order_by

string | null

null

ORDER BY句(例: "sync_date DESC"

count_karte_events - イベント件数集計

イベントの件数を集計します。GROUP BY にも対応しています。

パラメータ

デフォルト

説明

where_clause

string | null

null

WHERE条件

date_from

string | null

2日前

開始日(YYYYMMDD形式)

date_to

string | null

昨日

終了日(YYYYMMDD形式)

group_by

string | null

null

GROUP BY句(例: "event_name"

describe_karte_events_schema - スキーマ取得

KARTE イベントテーブルのカラム名・型・説明などのスキーマ情報を返します。パラメータはありません。

execute_karte_sql - カスタムSQL実行

任意の SQL を実行します。ガードレールが自動適用されます。

パラメータ

デフォルト

説明

sql

string

-

実行する SQL 文

dry_run

bool

false

true でスキャン量のみ確認

no_limit

bool

false

true で自動 LIMIT 付与をスキップ

使い方の例

Claude Code から自然言語で利用できます。

> KARTEの直近のイベントを10件見せて
→ query_karte_events(limit=10)

> クリックイベントだけを取得して
→ query_karte_events(where_clause="event_name = 'click'")

> event_name ごとのイベント数を集計して
→ count_karte_events(group_by="event_name")

> テーブルにどんなカラムがあるか教えて
→ describe_karte_events_schema()

> ユーザーごとのイベント数TOP10を出して
→ execute_karte_sql(sql="SELECT user_id, COUNT(*) as cnt FROM ... GROUP BY user_id ORDER BY cnt DESC LIMIT 10")

セキュリティ・ガードレール

機能

説明

破壊的SQL拒否

DROP, DELETE, INSERT, UPDATE, TRUNCATE, ALTER, CREATE を禁止

日付範囲制限

最大 30 日間まで

LIMIT 強制

カスタム SQL で未指定時に LIMIT 1000 を自動付与(no_limit=true でスキップ可)

_TABLE_SUFFIX 必須

ワイルドカードテーブルへのクエリに日付制約を強制

LIMIT 上限

1〜10000 の範囲に制限

サーバー単体起動

KARTE_API_KEY=<your-key> uv run karte-mcp-server

Cloud Run へのデプロイ

Cloud Run にデプロイすると、リモートの MCP サーバーとして複数のクライアントから利用できます。

1. server.py に HTTP トランスポートを追加

現在のサーバーは stdio トランスポートのみ対応しています。Cloud Run で使うには streamable-http トランスポートを追加します。

server.pymain() 関数を以下のように変更します。

import os

def main():
    """MCPサーバーを起動する."""
    transport = os.environ.get("MCP_TRANSPORT", "stdio")
    if transport == "streamable-http":
        _server.run(
            transport="streamable-http",
            host="0.0.0.0",
            port=int(os.environ.get("PORT", "8080")),
        )
    else:
        _server.run(transport="stdio")

2. Dockerfile を作成

プロジェクトルート(karte-datahub-mcp/)に Dockerfile を作成します。

FROM python:3.13-slim

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /app

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev

COPY src/ src/

ENV MCP_TRANSPORT=streamable-http
ENV PORT=8080

EXPOSE 8080

CMD ["uv", "run", "karte-mcp-server"]

3. デプロイ

# GCPプロジェクトの設定
export GCP_PROJECT=<your-gcp-project>
export REGION=asia-northeast1

# Cloud Run にデプロイ(ソースから直接ビルド)
gcloud run deploy karte-mcp-server \
  --source . \
  --project $GCP_PROJECT \
  --region $REGION \
  --set-env-vars "KARTE_API_KEY=<your-karte-api-key>,MCP_TRANSPORT=streamable-http,BQ_PROJECT=<your-bq-project>" \
  --no-allow-unauthenticated

サービスアカウントの認証情報は Cloud Run のデフォルトサービスアカウント、または --service-account で指定したサービスアカウントの権限が使われるため、CREDENTIAL_FILE の設定は不要です。対象の BigQuery データセットへの読み取り権限をサービスアカウントに付与してください。

4. Claude Code からリモートサーバーに接続

デプロイ後、.mcp.json にリモートサーバーとして登録します。

{
  "mcpServers": {
    "karte-bigquery": {
      "type": "streamable-http",
      "url": "https://<your-service-url>/mcp/",
      "headers": {
        "Authorization": "Bearer <id-token>"
      }
    }
  }
}

--no-allow-unauthenticated でデプロイした場合、認証トークンが必要です。以下で取得できます。

gcloud auth print-identity-token

または、認証付きプロキシ経由で接続する場合は gcloud run services proxy を利用します。

gcloud run services proxy karte-mcp-server \
  --project $GCP_PROJECT \
  --region $REGION \
  --port 8080

この場合、.mcp.json の URL は http://localhost:8080/mcp/ を指定します。

テスト

uv run pytest

技術スタック

  • FastMCP - MCP サーバーフレームワーク

  • google-cloud-bigquery - BigQuery SDK

  • Pydantic - データバリデーション

  • pytest / pytest-asyncio - テスト

Available Tools

4 tools
count_karte_eventsB

KARTEイベントの件数を取得する。

Args: where_clause: WHERE条件(例: "event_name = 'purchase'") date_from: 開始日 YYYYMMDD形式(デフォルト: 2日前) date_to: 終了日 YYYYMMDD形式(デフォルト: 昨日) group_by: GROUP BY句(例: "event_name")

ParametersJSON Schema
NameRequiredDescriptionDefault
where_clauseNo
date_fromNo
date_toNo
group_byNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.3/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the tool 'gets the count' which implies a read-only operation, but doesn't specify whether it requires authentication, has rate limits, returns paginated results, or what happens with null parameters. The default date values are mentioned, but other behavioral aspects are undocumented.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by parameter documentation. Each parameter explanation is concise and informative. While efficient, the Japanese-only text might limit accessibility for non-Japanese speaking agents, and the structure could be slightly improved with clearer section headers.

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

Completeness3/5

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

Given that an output schema exists, the description doesn't need to explain return values. However, for a 4-parameter counting tool with no annotations, the description should ideally provide more behavioral context about what 'count' means (e.g., is it aggregated counts when using group_by?). The parameter documentation is excellent, but overall context about the tool's behavior remains incomplete.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing clear semantic information for all 4 parameters. It explains what each parameter does, provides example syntax ('event_name = "purchase"'), specifies date format requirements (YYYYMMDD), and documents default values (2 days ago for date_from, yesterday for date_to). This adds significant value beyond the bare schema.

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 clearly states the tool's purpose: 'KARTEイベントの件数を取得する' (Get the count of KARTE events). It specifies the verb ('取得する' - get/count) and resource ('KARTEイベント' - KARTE events), making the purpose unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'query_karte_events' which might also retrieve event data.

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 sibling tools like 'query_karte_events' or 'execute_karte_sql', nor does it specify use cases, prerequisites, or exclusions. The parameter documentation implies filtering and grouping capabilities, but no contextual usage instructions are provided.

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

describe_karte_events_schemaA

KARTEイベントテーブルのスキーマを取得する。

テーブルのカラム名、型、説明等のメタデータを返す。

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior3/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. It states that the tool retrieves metadata including column names, types, and descriptions, which implies a read-only operation. However, it doesn't cover aspects like error handling, authentication needs, rate limits, or response format details beyond metadata. The description adds some context but lacks comprehensive behavioral traits.

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 concise and well-structured, consisting of two sentences that directly state the purpose and what is returned. There is no wasted language or redundancy, and it is front-loaded with the main action. Every sentence earns its place by adding clear information.

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 tool's complexity is low (0 parameters, read-only operation) and an output schema exists, the description is reasonably complete. It explains the purpose and the type of metadata returned, which aligns with the output schema's role in detailing return values. However, it could be more complete by addressing usage context or behavioral aspects like error cases, but for a simple schema retrieval tool, it's adequate.

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 has 0 parameters with 100% coverage, meaning no parameters are documented in the schema. The description doesn't mention any parameters, which is appropriate since none exist. It adds value by explaining what metadata is returned (column names, types, descriptions), compensating for the lack of parameter documentation. Baseline is 4 for 0 parameters, as the description provides useful output semantics.

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 clearly states the tool's purpose: 'KARTEイベントテーブルのスキーマを取得する' (Get the schema of the KARTE events table). It specifies the verb '取得する' (get/retrieve) and the resource 'スキーマ' (schema), making it understandable. However, it doesn't explicitly differentiate from sibling tools like 'query_karte_events' or 'execute_karte_sql', which might also involve schema-related operations indirectly.

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 mentions what the tool does but doesn't specify scenarios for usage, prerequisites, or exclusions. Given sibling tools like 'count_karte_events' and 'query_karte_events', there's no indication of when schema retrieval is preferred over data querying or counting.

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

execute_karte_sqlA

カスタムSQLを実行する(ガードレール付き)。

krt_pockyevent_v1_* テーブルへのクエリには _TABLE_SUFFIX 制約が必須。 LIMIT未指定時は自動で LIMIT 1000 が付与される。 破壊的SQL(DROP, DELETE等)は拒否される。

Args: sql: 実行するSQL文 dry_run: Trueの場合、スキャン量のみ確認する no_limit: Trueの場合、自動LIMIT付与をスキップする

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYes
dry_runNo
no_limitNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A5/5.0
Behavior5/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure and excels. It reveals critical behavioral traits: guardrails on SQL execution, mandatory constraints for specific tables, automatic LIMIT application (1000) by default, rejection of destructive SQL operations, and the dry_run option for scanning only. This provides comprehensive insight into how the tool behaves beyond basic execution.

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 appropriately sized and front-loaded: it starts with the core purpose, followed by key behavioral rules, and ends with a structured Args section. Every sentence earns its place by providing critical information without redundancy, making it efficient and easy to parse for an AI agent.

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

Completeness5/5

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

Given the complexity of a SQL execution tool with 3 parameters, 0% schema coverage, no annotations, but an output schema present, the description is complete enough. It covers purpose, usage rules, behavioral constraints, and parameter semantics thoroughly. The output schema handles return values, so the description doesn't need to explain them, making this a well-rounded specification.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate fully, which it does. The Args section explicitly explains each parameter's semantics: 'sql' is the SQL statement to execute, 'dry_run' confirms scan volume only when True, and 'no_limit' skips automatic LIMIT addition when True. This adds essential meaning beyond the bare schema, clarifying how parameters affect tool behavior.

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 the tool's purpose: 'カスタムSQLを実行する(ガードレール付き)' (Execute custom SQL with guardrails). It specifies the verb (execute) and resource (custom SQL) and distinguishes it from sibling tools like count_karte_events, describe_karte_events_schema, and query_karte_events by focusing on raw SQL execution rather than predefined queries or metadata operations.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines: it states when to use specific constraints ('krt_pockyevent_v1_* テーブルへのクエリには _TABLE_SUFFIX 制約が必須' - queries to krt_pockyevent_v1_* tables require _TABLE_SUFFIX constraint), when alternatives apply (automatic LIMIT 1000 unless no_limit is True), and exclusions ('破壊的SQL(DROP, DELETE等)は拒否される' - destructive SQL like DROP, DELETE is rejected). This clearly guides when and how to use this tool versus other approaches.

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

query_karte_eventsA

KARTEイベントデータを取得する。

日付制約は自動的に適用される(デフォルト: 2日前〜昨日)。

Args: select_columns: SELECT句(デフォルト: "*") where_clause: 追加WHERE条件(例: "event_name = 'click'") date_from: 開始日 YYYYMMDD形式(デフォルト: 2日前) date_to: 終了日 YYYYMMDD形式(デフォルト: 昨日) limit: 取得件数上限 1〜10000(デフォルト: 100)。Noneで制限なし order_by: ORDER BY句(例: "sync_date DESC")

ParametersJSON Schema
NameRequiredDescriptionDefault
select_columnsNo*
where_clauseNo
date_fromNo
date_toNo
limitNo
order_byNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.8/5.0
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: automatic date constraints with defaults, parameter defaults, and limit range (1-10000). However, it doesn't mention important aspects like whether this is a read-only operation, potential rate limits, authentication requirements, or what happens with large result sets beyond the limit parameter. The description adds useful context but leaves significant gaps.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by detailed parameter documentation. It's appropriately sized for a 6-parameter tool. The only minor improvement would be front-loading more critical behavioral information before the parameter details, but overall it's efficient with minimal waste.

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 tool's complexity (6 parameters, no annotations, but with output schema), the description is quite complete. It thoroughly documents all parameters and their semantics. The presence of an output schema means the description doesn't need to explain return values. The main gap is lack of behavioral context around permissions, rate limits, or error conditions, but the parameter documentation is comprehensive.

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

Parameters5/5

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

The schema description coverage is 0%, so the description must fully compensate. It does this excellently by providing detailed parameter documentation in the Args section: each parameter's purpose, format examples (YYYYMMDD, 'event_name = "click"'), default values, constraints (limit 1-10000), and special cases (None for no limit). This adds substantial meaning beyond what the bare schema provides.

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 clearly states the tool's purpose: 'KARTEイベントデータを取得する' (retrieve KARTE event data). It specifies the verb (retrieve) and resource (KARTE event data). However, it doesn't explicitly differentiate from sibling tools like count_karte_events or execute_karte_sql, which prevents a perfect score.

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?

The description provides some usage context by mentioning automatic date constraints (default: 2 days ago to yesterday), which helps understand when to use it for date-filtered queries. However, it doesn't explicitly state when to use this tool versus alternatives like count_karte_events (for counting) or execute_karte_sql (for custom SQL), leaving the guidelines somewhat implied rather than explicit.

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

TDQS

A3.8/5.0
Disambiguation4/5

The tools are mostly distinct: count_karte_events counts events, describe_karte_events_schema provides metadata, execute_karte_sql runs custom SQL, and query_karte_events retrieves event data. However, query_karte_events and execute_karte_sql could be confused as both retrieve data, though execute_karte_sql is more flexible with custom SQL while query_karte_events has structured parameters. The descriptions help clarify their boundaries.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern with snake_case: count_karte_events, describe_karte_events_schema, execute_karte_sql, and query_karte_events. The naming is predictable and readable throughout the set.

Tool Count4/5

With 4 tools, the count is reasonable for a data query server focused on KARTE events. It covers core operations like counting, describing schema, querying, and custom SQL execution. It might benefit from additional tools for more advanced analytics or data manipulation, but the scope is well-defined and manageable.

Completeness3/5

The toolset covers basic read operations for KARTE event data, including counting, schema description, structured querying, and custom SQL. However, there are notable gaps: no tools for writing or updating data (e.g., inserting or modifying events), and limited to event data without broader data management capabilities. Agents can work around this for query tasks but may fail for data manipulation needs.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables natural language exploration and querying of Google BigQuery datasets through four tools: listing datasets, inspecting table schemas, generating SQL queries with LLM assistance, and executing approved queries.
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI assistants to query and analyze Google BigQuery data, including schema browsing, running queries, and comparing datasets through natural language.
    MIT

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/YusukeYajima/karte-datahub-mcp'

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