typespec-create-api-plugin について
typespec-create-api-plugin は、TypeSpec で Microsoft 365 Copilot の API プラグインを作成するスキルです。外部 REST API を Copilot に接続する開発者向けに、エージェント定義と操作定義を生成し、認証やレスポンスカードの設定を扱います。
主な機能
- 01main.tsp のエージェント定義を生成
- 02actions.tsp の API 操作を生成
- 03API Key、OAuth2 などの認証設定
- 04操作確認と Adaptive Cards の設定
- 05推論と応答の指示を追加
- 06REST 規約に沿った操作の記述
活用シーン
- 01REST API 用の Copilot プラグイン作成
- 02API に応じた認証方式の選択
- 03重要な操作に確認を要求
- 04結果を Adaptive Cards で表示
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ github/ awesome-copilot --skill typespec-create-api-pluginインストール後、Claude Code で/typespec-create-api-pluginを入力して読み込まれたか確認します。
詳細
TypeSpec API プラグインを作成する
外部 REST API と統合する、Microsoft 365 Copilot 用の完全な TypeSpec API プラグインを作成します。
要件
次の内容を含む TypeSpec ファイルを生成します。
main.tsp - エージェント定義
import "@typespec/http";
import "@typespec/openapi3";
import "@microsoft/typespec-m365-copilot";
import "./actions.tsp";
using TypeSpec.Http;
using TypeSpec.M365.Copilot.Agents;
using TypeSpec.M365.Copilot.Actions;
@agent({
name: "[Agent Name]",
description: "[Description]"
})
@instructions("""
[Instructions for using the API operations]
""")
namespace [AgentName] {
// Reference operations from actions.tsp
op operation1 is [APINamespace].operationName;
}
actions.tsp - API 操作
import "@typespec/http";
import "@microsoft/typespec-m365-copilot";
using TypeSpec.Http;
using TypeSpec.M365.Copilot.Actions;
@service
@actions(#{
nameForHuman: "[API Display Name]",
descriptionForModel: "[Model description]",
descriptionForHuman: "[User description]"
})
@server("[API_BASE_URL]", "[API Name]")
@useAuth([AuthType]) // Optional
namespace [APINamespace] {
@route("[/path]")
@get
@action
op operationName(
@path param1: string,
@query param2?: string
): ResponseModel;
model ResponseModel {
// Response structure
}
}
認証オプション
API の要件に基づいて選択します。
-
認証なし (パブリック API)
// No @useAuth decorator needed -
API キー
@useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-API-Key">) -
OAuth2
@useAuth(OAuth2Auth<[{ type: OAuth2FlowType.authorizationCode; authorizationUrl: "https://oauth.example.com/authorize"; tokenUrl: "https://oauth.example.com/token"; refreshUrl: "https://oauth.example.com/token"; scopes: ["read", "write"]; }]>) -
登録済み認証リファレンス
@useAuth(Auth) @authReferenceId("registration-id-here") model Auth is ApiKeyAuth<ApiKeyLocation.header, "X-API-Key">
機能のケイパビリティ
確認ダイアログ
@capabilities(#{
confirmation: #{
type: "AdaptiveCard",
title: "Confirm Action",
body: """
Are you sure you want to perform this action?
* **Parameter**: {{ function.parameters.paramName }}
"""
}
})
Adaptive Card レスポンス
@card(#{
dataPath: "$.items",
title: "$.title",
url: "$.link",
file: "cards/card.json"
})
推論と応答の指示
@reasoning("""
Consider user's context when calling this operation.
Prioritize recent items over older ones.
""")
@responding("""
Present results in a clear table format with columns: ID, Title, Status.
Include a summary count at the end.
""")
ベストプラクティス
- 操作名: 明確でアクション指向の名前を使用します (listProjects、createTicket)
- モデル: リクエストとレスポンス用に TypeScript ライクなモデルを定義します
- HTTP メソッド: 適切な動詞を使用します (@get、@post、@patch、@delete)
- パス: @route を使って RESTful なパス規則を使用します
- パラメーター: @path、@query、@header、@body を適切に使用します
- 説明: モデルを理解しやすくするために明確な説明を提供します
- 確認: 破壊的な操作 (削除、重要なデータの更新) に追加します
- カード: 複数のデータ項目を含むリッチな視覚的レスポンスに使用します
ワークフロー
ユーザーに確認します。
- API のベース URL と目的は何ですか?
- どのような操作が必要ですか (CRUD 操作)?
- API はどの認証方法を使用しますか?
- いずれかの操作に確認を必須にしますか?
- レスポンスに Adaptive Card が必要ですか?
次に、以下を生成します。
- エージェント定義を含む完全な
main.tsp - API 操作とモデルを含む完全な
actions.tsp - Adaptive Card が必要な場合はオプションの
cards/card.json
コメント
Markdown 対応