0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【完全ガイド】DatabuttonでMCPを使う方法|AIエージェントにツールを持たせる最速の方法

Posted at

🧠 MCPとは?

**MCP(Model Context Protocol)**は、ChatGPTのようなAIエージェントが
あなたが作ったツール(関数やAPI)を自動で使えるようにするための仕組みです。

Databuttonでは、これをノーコード的なUI+コード少なめで実装できます。

💡 できることの例
• AIが「PDFを要約する関数」を呼び出す
• AIが「Firestoreから情報を検索」して返す
• AIが「スプレッドシートにデータを書き込む」
• AIが「天気APIを叩いて、気温に応じて服を提案」

🚀 全体の流れ(図解イメージ)

ChatGPT / LangChain Agent

MCPサーバー(Databuttonアプリ)

あなたが定義したカスタム関数やAPI

✅ Step 1: Databuttonアプリを作る
1. Databutton にログイン(無料)
2. 新規アプリを作成(例:mcp-demo)

✅ Step 2: MCPツールを定義する

main.py を以下のように編集します:

from databutton import Tool

@Tool()
def greet(name: str):
"""Return a friendly greeting"""
return f"Hello, {name}!"

これだけで、**greet() がAIエージェントから呼び出せる「ツール」**になります。

✅ Step 3: 公開してMCPサーバーにする

アプリを Publish すると、こんなURLが発行されます:

このURLが AI側から呼び出すためのMCPサーバーエンドポイントです。

✅ Step 4: LangChainから呼び出してみる(例)

from langchain.agents import initialize_agent
from langchain.tools.mcp import MCPToolkit

tools = MCPToolkit.from_url("https://your-app.databutton.app/mcp")
agent = initialize_agent(tools, llm) # llmはOpenAIなど

agent.run("Greet someone named Satoshi")

LangChain側からは「ツール」として自動認識されます 🎉

🔐 認証やセキュリティは?
• Firebase Authentication や Secret を使ってAPIを保護できます。
• 特定ユーザーだけが使えるようにすることも可能です。

📦 応用:複数ツールもOK

@Tool()
def add(a: int, b: int):
return a + b

@Tool()
def subtract(a: int, b: int):
return a - b

MCPはツールのコレクションを自動でまとめて公開します。

🧪 実用例(アイデア)
• 「ChatGPTからFirestore検索」
• 「ユーザー入力をスプレッドシートに追加」
• 「AIがSlackに投稿するWebhookを呼ぶ」

📘 関連リンク

✅ まとめ

ポイント 内容
MCPとは AIにツールを与えるプロトコル
Databuttonとは MCPサーバーをノーコード感覚で構築できるプラットフォーム
実装方法 @Tool() で関数を定義 → 公開URLから接続
AI活用が加速 ChatGPTやLangChainと自作APIを接続できる世界へ!

🙌 最後に

AIに「自作の能力」を持たせたいなら、MCP+Databuttonが今もっとも手軽で強力な選択肢です。
ChatGPTに「PDFを要約させたい」「業務DBを検索させたい」と思ったら、まずここから始めましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?