ローカルハンドラーの開発とテスト development

IMPORTANT
Adobe LLM Appsは現在Betaにいます。
ここに示す機能、ワークフロー、UIは、必ずしも製品の最終状態を表すものではありません。 Betaに参加するには、llm-apps-beta@adobe.comに電子メールを送信します。

この参照は、ハンドラーをローカルで開発する際に使用します。 ハンドラー結果コントラクトについては、生成されたハンドラーのカスタマイズ ​を参照してください。

要件

  • Node.js 24以降。
  • npm:
  • リンクされたハンドラーリポジトリのローカルクローン。

プロジェクト構造

リンクされたリポジトリは、次のレイアウトに従います。

your-llm-app/
├── entry.js                   # Webpack entry — do not modify
├── actions/                   # One folder per action
│   └── echo/
│       └── index.js           # Example handler
├── test/
│   ├── actions/
│   │   └── echo.test.js
│   ├── fixtures/
│   │   └── actions.json
│   ├── html-transform.js
│   ├── jest.setup.js
│   └── server.test.js
├── server/
│   └── local.js               # Local dev server (port 9080)
├── actions.json               # Gitignored — optional local metadata
├── app.config.yaml            # Adobe I/O Runtime config
├── webpack.config.js
└── package.json

重要なポイント:

  • entry.js​はwebpack エントリポイントです。 ビルド時には、すべてのactions/*/index.js ファイルが検出され、1つのdist/index.jsにバンドルされます。 修正しないでください。
  • actions.json​は許可されています。 デプロイメントパイプラインは、LLM Appsのアクションメタデータから自動的に書き込みます。
  • テスト​は、actions/内のtest/actions/ではなく​に存在します。 Webpackはactions/以下のすべての要素をデプロイ済みのアーティファクトにバンドルします。テストを共同で配置すると、Adobe I/O Runtimeに送信されます。

ローカル開発

Adobeの資格情報を使用せずに、ローカルでハンドラーを開発およびテストできます。

npm install
npm run dev:local

これにより、webpackでプロジェクトが構築され、http://localhost:9080にプレーン Node.js HTTP サーバーが開始されます。 サーバーはactions/の下にあるハンドラーファイルを自動検出し、MCP ツールとして登録します。

ローカルメタデータの動作

現在のUIにはactions.json ダウンロードが提供されていません。 このファイルを使用せずにローカルサーバーを実行できます。actions/以下のハンドラーを検出し、最小限のメタデータで登録します。

actions.jsonがない場合、UI入力スキーマに対してローカル アクション引数は検証されません。 単体テストと統合テストでは、代表的なメタデータにtest/fixtures/actions.jsonを使用します。

curlでテスト

# List all registered tools
curl -sX POST "http://localhost:9080" \
  -H 'content-type: application/json' \
  -H 'accept: application/json;q=1.0, text/event-stream;q=0.5' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

# Call the boilerplate echo action
curl -sX POST "http://localhost:9080" \
  -H 'content-type: application/json' \
  -H 'accept: application/json;q=1.0, text/event-stream;q=0.5' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"echo","arguments":{"message":"hello"}}}'

MCP Inspectorを使用したテスト

npx @modelcontextprotocol/inspector

Transport Type​をstreamable-httpに、URL​をhttp://localhost:9080に設定します。

テスト

ハンドラー単体テストはtest/actions/の下にあり、actions/ レイアウトをミラーリングします。

// test/actions/echo.test.js
const handler = require('../../actions/echo/index.js')

test('echoes the message', async () => {
  const result = await handler({ message: 'hello' })
  expect(result.content[0].text).toBe('Echo: hello')
})

test('always returns content parts', async () => {
  const result = await handler({})
  expect(Array.isArray(result.content)).toBe(true)
})

次を使用してテストを実行:

npm test                                      # all tests
npx jest test/actions/echo                   # one action only

ローカルテストが合格したら、変更をプッシュして変更をデプロイ ​します。

recommendation-more-help
llm-apps-help-main-toc