カスタムZendesk MCPサーバの作成
MCPサーバを作成し、Zendeskインスタンスと連携するSquidエージェントに接続
作成するもの
- Zendeskと連携するために、カスタムSquid MCPサーバに接続するシンプルなエージェント
- チケットの作成、チケットステータスの更新、およびチケットへのコメント追加
このチュートリアルでは、以下の機能を使用します:
| AI Abilities | Internal Connectors |
|---|---|
| Model Context Protocol ability | Model Context Protocol server |
学習できる内容
- Squidのbackend SDKを使用して、MCPサーバを作成しエージェントに接続する方法
必要なもの
- The Squid CLI
- Squid Console のアカウント
- Zendesk account
- TypeScriptの経験
Squidアプリの作成
- Squid Console に移動し、Zendesk MCP Tutorial という名前の新しいSquidアプリケーションを作成します。
- アプリケーションの概要ページで、Backend project セクションまでスクロールします。Initialize Backend をクリックし、初期化コマンドをコピーします。
- プロジェクトを配置する任意のディレクトリで、ターミナルから初期化コマンドを実行します。
Zendeskプロジェクトのセットアップ
スターターバックエンドのSquidを手に入れたので、これをカスタマイズしてZendeskに接続するMCPサーバを作成できます。
Zendeskと連携する方法はいくつかありますが、このチュートリアルではNode Zendesk API client を使用してZendesk APIを呼び出します。
-
好みのIDEでプロジェクトを開きます。クライアントをインストールするには、ターミナルで以下のコマンドを実行してください:
npm install node-zendeskまた、以下の設定を含めるために
tsconfig.jsonファイルを更新する必要があります:{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "nodenext"
}
} -
src/service/example-service.tsをzendesk-mcp.service.tsにリネームし、クラス名をZendeskMcpServiceに更新します。 -
src/service/index.tsファイルを更新して、新しいサービスをエクスポートします:export * from './zendesk-mcp.service.ts'; -
srcディレクトリ内にprovidersという新しいディレクトリを作成します。そのprovidersディレクトリ内にzendesk.provider.tsというファイルを作成します。このファイルには、Node Zendesk client を使用してZendesk APIと連携するロジックが含まれます。基本的な関数として、AIエージェントがチケットにコメントを追加しステータスを更新できるreplyToTicketと、チケットを作成するcreateTicketがあります。src/providers/zendesk.provider.tsに以下のコードを追加してください:import { createClient, ZendeskClient } from 'node-zendesk';
import {
CreateOrUpdateTicket,
Status,
Ticket,
TicketComment,
} from 'node-zendesk/clients/core/tickets';
export class ZendeskProvider {
private readonly zendeskClient: ZendeskClient;
constructor(username: string, token: string, subdomain: string) {
this.zendeskClient = createClient({ username, token, subdomain });
}
async replyToTicket(
ticketId: number,
replyText: string,
isReplyToCustomer: boolean,
reassignToEmail: string | undefined,
status: Status | undefined,
): Promise<TicketComment | undefined> {
const comment: Partial<TicketComment> = {
html_body: replyText,
public: isReplyToCustomer,
};
const response = await this.zendeskClient.tickets.update(ticketId, {
ticket: { comment, status: status, assignee_email: reassignToEmail },
});
return response.result.comment;
}
async createTicket(
subject: string,
text: string,
requesterId: number,
): Promise<Ticket | undefined> {
const ticketData: CreateOrUpdateTicket = {
ticket: {
subject,
description: text,
requester_id: requesterId,
},
};
const response = await this.zendeskClient.tickets.create(ticketData);
return response.result;
}
}さらに、MCPサーバを保護するために、
@mcpAuthorizerデコレーターを使用して認可されたユーザーのみアクセスできるように制限します。createTicketメソッドの下に、以下のコードを追加してください:import { mcpAuthorizer } from '@squidcloud/backend';
export class ZendeskProvider {
// existing code...
@mcpAuthorizer()
async authorizeMcp(request: McpAuthorizationRequest): Promise<boolean> {
const authHeader = request.headers['authorization'];
if (!authHeader) return false;
const [scheme, token] = authHeader.split(' ');
return scheme === 'Bearer' && token === 'some_secure_auth_value';
}
} -
Zendesk APIを使用するには、Zendesk APIキーを提供する必要があります。Zendesk APIキーを作成するには、Zendesk documentation の手順に従ってください。次に、Squid Consoleの左側サイドバーにある Secrets ページに移動します。Store New Secret をクリックし、以下の値を追加してください:
- Secret key:
ZENDESK_API_KEY - Value: Your Zendesk API key
さらに、正しい認証値を含む2つ目のシークレットを追加してください:
- Secret key:
MCP_AUTH_VALUE - Value:
Bearer some_secure_auth_value(またはその他の安全な値。ただし、上記のauthorizeMcpメソッド内の値と一致させる必要があります)
- Secret key:
-
base-zendesk.service.tsという新しいサービスファイルを作成します。このファイルには、必要な認証情報で初期化されたベースZendeskプロバイダーが含まれます。src/service/base-zendesk.service.tsに、あなたの認証情報を用いて以下のコードを追加してください:import { SquidService } from '@squidcloud/backend';
import { ZendeskProvider } from '../providers/zendesk.provider';
export class BaseZendeskService extends SquidService {
protected readonly zendeskProvider = new ZendeskProvider(
'YOUR_ZENDESK_EMAIL',
this.secrets['ZENDESK_API_KEY'] as string,
'YOUR_ZENDESK_SUBDOMAIN', // 例: 'mycompany' (Zendesk URLが 'mycompany.zendesk.com'の場合)
);
}
これらの手順に従うことで、カスタムZendesk MCPサーバを作成するために必要なすべてのコンポーネントが揃いました。
Squid + Zendesk MCPサーバの作成
-
zendesk-mcp.service.tsファイルを開き、チケット作成と返信のツールを備えたMCPサーバを作成するため、以下のコードを追加してください。@mcpServerデコレーターを使用することで、AIエージェントが利用できるMCPサーバが構築されます。import { mcpServer, mcpTool } from '@squidcloud/backend';
import { BaseZendeskService } from './base-zendesk.service';
@mcpServer({
name: 'zendesk-mcp',
id: 'zendesk-mcp',
description: 'This MCP knows how to communicate with Zendesk',
version: '1.0.0'
})
export class ZendeskMcpService extends BaseZendeskService {
} -
@mcpToolデコレーターは、AIエージェントが実行できる具体的なアクションを定義します。最初に追加するツールはZendeskのチケットを作成するものです。ZendeskMcpServiceクラス内に以下のコードを追加してください:export class ZendeskMcpService extends BaseZendeskService {
@mcpTool({
description: 'This tool creates a Zendesk ticket',
inputSchema: {
type: 'object',
properties: {
title: {
type: 'string',
description: 'The title of the ticket to create',
},
text: {
type: 'string',
description: 'The text of the ticket to create',
},
userId: {
type: 'number',
description: 'The user ID who is requesting to create the ticket',
}
},
required: ['title', 'text', 'userId'],
},
})
async createTicket({ title, text, userId }) {
return await this.zendeskProvider.createTicket(title, text, userId);
}
} -
さらに、チケットへの返信とステータス更新ができるツールをもう1つ作成します:
export class ZendeskMcpService extends BaseZendeskService {
@mcpTool({
description: 'This tool replies to a Zendesk ticket',
inputSchema: {
type: 'object',
properties: {
ticketId: {
type: 'number',
description: 'The ID of the ticket to reply to',
},
replyText: {
type: 'string',
description: 'The text of the reply to the ticket',
},
isReplyToCustomer: {
type: 'boolean',
description: 'Whether the reply is public (to customer) or private (internal note)',
},
status: {
type: 'string',
enum: ['new', 'open', 'pending', 'hold', 'solved', 'closed'],
description: 'The status to set the ticket to',
},
},
required: ['ticketId', 'replyText', 'isReplyToCustomer'],
},
})
async replyToTicket({ ticketId, replyText, isReplyToCustomer, status }) {
try {
await this.zendeskProvider.replyToTicket(ticketId, replyText, isReplyToCustomer, undefined, status);
return { success: true };
} catch (error) {
throw new Error(error);
}
}
}
AIエージェントをMCPサーバに接続する
カスタムZendesk MCPサーバを作成したので、これにAIエージェントを接続できます。
エージェントにサーバを公開するために、バックエンドをデプロイする必要があります。
-
まず、実行中のローカルバックエンドをターミナルで
CTRL + Cを押して停止し、以下のコマンドを実行します:squid deploy -
次に、Squid Consoleの Connectors タブに移動し、Available Connectors をクリックします。MCPコネクタを見つけ、Add Connector をクリックしてください。
-
以下のコネクタ情報を入力します:
- Connector ID: 任意の一意のID(例:
zendesk-mcp。短く意味のあるIDが望ましい) - MCP URL: デプロイしたバックエンドから提供されたMCPエンドポイントURL。MCP URLを確認するには、コンソールの Backend タブに移動し、MCP Servers の下から探してください。
次に、Authorization をオンにし、以下の詳細を入力します:
- Authorization Header:
Authorization - Authorization Value: 先ほど作成した
MCP_AUTH_VALUEシークレット
- Connector ID: 任意の一意のID(例:
-
Test Connection をクリックしてサーバへの接続をテストします。接続に失敗した場合は、MCP URLの値を確認してください。接続が成功したら、Add Connector をクリックします。
MCPコネクタを追加したので、これを利用するAIエージェントを作成する時が来ました。
-
Squid Consoleの Agent Studio タブに移動し、Create New Agent をクリックします。
-
以下の詳細を入力します:
- Agent ID: 例として
Zendesk Agentなど、エージェントの名前 - Agent Description: 例として
An agent that can create and reply to Zendesk ticketsなど、エージェントの説明 そして、Create をクリックします。
- Agent ID: 例として
-
エージェントの Overview タブで、Add Abilities をクリックし、MCP アビリティを選択します。すると、先ほど作成した
zendesk-mcpコネクタが含まれるドロップダウンが表示されます。これを選択して Add Connector をクリックしてください。その後、エージェントがいつこのMCPサーバを呼び出すべきかについて、以下の指示を追加します:Use this MCP server when prompted to interact with Zendesk
これで、エージェントはZendesk MCPサーバを使用する準備が整いました!
エージェントのテスト
エージェントをテストするには、Agent Studioの Test Agent タブに移動します。エージェントにチケットの作成や返信を依頼して対話することができます。以下は使用できる例のプロンプトです:
以下の詳細でチケットを作成してください -
Title: 'Bug report'
Text: 'User reported login feature is not currently working'
User ID: (あなたのUser ID。Zendeskのプロフィールに移動してURLからIDの値をコピーすることで確認できます)
チケットID(前のステップで作成されたチケットのID)を更新し、以下の詳細で顧客に返信してください -
Text: 'The login issue has been resolved. Please try again.'
Status: solved
次のステップ
カスタムZendesk MCPサーバを作成し、AIエージェントに接続できたことをお祝いします!この基盤を活用して、MCPサーバにさらに多くのツールを追加したり、AIエージェントの機能を強化したりすることができます。
- Squid AIエージェントの詳細については、documentation をご覧ください。
- Squidのリアルタイムデータ機能の詳細については、Client SDK documentation をご覧ください。
- 独自のデータソースと統合する方法については、database connectors documentation をご覧ください。