本機處理常式開發與測試 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檔案,並將它們整合到單一dist/index.js中。 請勿修改。
  • actions.json​已授權。 部署管道會自動從LLM Apps中的動作中繼資料寫入它。
  • 測試​在test/actions/下存放,不在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檢查器測試

npx @modelcontextprotocol/inspector

將​ 傳輸型別 ​設定為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