@emseepea/create-api-backed-server 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,8 +6,8 @@ This directory is both the maintained example and its public npm initializer.
6
6
 
7
7
  Use this template when a tool calls a public JSON API and must validate and
8
8
  select the fields returned to the caller. Choose the [tool server](../tool-server/README.md)
9
- when all data is local, or the [sign-in tool server](../sign-in-tool-server/README.md)
10
- when calling the tool requires authentication. [Compare all eight templates](https://emseepea.github.io/emseepea/examples/).
9
+ when all data is local. Add authentication to either template when calling the
10
+ tool requires permission. [Compare all templates](https://emseepea.github.io/emseepea/examples/).
11
11
 
12
12
  ## Create a Project
13
13
 
@@ -17,6 +17,30 @@ npm init @emseepea/api-backed-server -- my-server
17
17
 
18
18
  <!-- generated-project-readme -->
19
19
 
20
+ ## Choose Open or Protected Access
21
+
22
+ Start open when the catalogue and operations are public.
23
+
24
+ To protect this template, pass both options to the app factory:
25
+
26
+ - `access: { access: "protected", requiredScopes: ["peas:read"] }`
27
+ - an `authentication` adapter
28
+
29
+ Keep `authentication.discovery` as `"public"` unless capability names or
30
+ schemas are sensitive. Use `"protected"` only when each principal should see a
31
+ permission-filtered catalogue. OAuth metadata remains public in both modes.
32
+
33
+ ## Add Observability
34
+
35
+ The same factory accepts `observability`.
36
+
37
+ - Use `structuredLogging` for safe structured events.
38
+ - Use `openTelemetry` for traces and metrics.
39
+
40
+ Adapters receive only redacted framework events. They never receive request
41
+ bodies, arguments, results, tokens, provider claims, or raw errors. See the
42
+ [server API](https://github.com/emseepea/emseepea/tree/main/packages/framework#authentication-and-observability) for the complete configuration.
43
+
20
44
  ## Public Web Service Backend Example
21
45
 
22
46
  Choose this example when your MCP tool needs to read a public web service and
@@ -1,4 +1,28 @@
1
- # Public Web Service Backend Example
1
+ # Choose Open or Protected Access
2
+
3
+ Start open when the catalogue and operations are public.
4
+
5
+ To protect this template, pass both options to the app factory:
6
+
7
+ - `access: { access: "protected", requiredScopes: ["peas:read"] }`
8
+ - an `authentication` adapter
9
+
10
+ Keep `authentication.discovery` as `"public"` unless capability names or
11
+ schemas are sensitive. Use `"protected"` only when each principal should see a
12
+ permission-filtered catalogue. OAuth metadata remains public in both modes.
13
+
14
+ ## Add Observability
15
+
16
+ The same factory accepts `observability`.
17
+
18
+ - Use `structuredLogging` for safe structured events.
19
+ - Use `openTelemetry` for traces and metrics.
20
+
21
+ Adapters receive only redacted framework events. They never receive request
22
+ bodies, arguments, results, tokens, provider claims, or raw errors. See the
23
+ [server API](https://github.com/emseepea/emseepea/tree/main/packages/framework#authentication-and-observability) for the complete configuration.
24
+
25
+ ## Public Web Service Backend Example
2
26
 
3
27
  Choose this example when your MCP tool needs to read a public web service and
4
28
  return selected, checked data in a clear result for an assistant.
@@ -14,7 +14,7 @@
14
14
  "lint": "oxlint src test eval test-support"
15
15
  },
16
16
  "devDependencies": {
17
- "@emseepea/testing": "0.5.2",
17
+ "@emseepea/testing": "0.6.1",
18
18
  "@modelcontextprotocol/client": "2.0.0",
19
19
  "@types/node": "24.13.3",
20
20
  "typescript": "6.0.3",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "private": true,
27
27
  "dependencies": {
28
- "@emseepea/server": "0.3.3",
28
+ "@emseepea/server": "0.4.0",
29
29
  "zod": "4.4.3"
30
30
  }
31
31
  }
@@ -1,11 +1,25 @@
1
- import { createEmseepea, discoverCapabilities } from "@emseepea/server";
1
+ import {
2
+ createEmseepea,
3
+ discoverCapabilities,
4
+ type AccessPolicy,
5
+ type EmseepeaExtensions,
6
+ } from "@emseepea/server";
2
7
  import type { JsonHttpClient } from "@emseepea/server/http";
3
8
 
4
- export async function createBackendExample(client: JsonHttpClient): Promise<ReturnType<typeof createEmseepea>> {
9
+ export interface BackendExampleOptions extends EmseepeaExtensions {
10
+ readonly access?: AccessPolicy;
11
+ }
12
+
13
+ export async function createBackendExample(
14
+ client: JsonHttpClient,
15
+ options: BackendExampleOptions = {},
16
+ ): Promise<ReturnType<typeof createEmseepea>> {
17
+ const { access = { access: "public" }, ...extensions } = options;
5
18
  return createEmseepea({
6
19
  name: "emseepea-api-backed-server",
7
20
  version: "0.0.0",
8
21
  instructions: "Use search-pea-taxa to search iNaturalist's public taxon catalogue for pea species.",
9
- ...await discoverCapabilities(new URL("./capabilities/", import.meta.url), { client }),
22
+ ...await discoverCapabilities(new URL("./capabilities/", import.meta.url), { client, access }),
23
+ ...extensions,
10
24
  });
11
25
  }
@@ -1,8 +1,11 @@
1
- import { defineMappedTool, type CapabilityModuleFactory } from "@emseepea/server";
1
+ import { defineMappedTool, type AccessPolicy, type CapabilityModuleFactory } from "@emseepea/server";
2
2
  import type { JsonHttpClient } from "@emseepea/server/http";
3
3
  import { z } from "zod";
4
4
 
5
- export interface BackendExampleContext { readonly client: JsonHttpClient }
5
+ export interface BackendExampleContext {
6
+ readonly client: JsonHttpClient;
7
+ readonly access: AccessPolicy;
8
+ }
6
9
 
7
10
  const backendTaxon = z.object({
8
11
  id: z.number().int().positive().describe("iNaturalist identifier for the taxon."),
@@ -35,9 +38,9 @@ const backendInputSchema = z.object({
35
38
  });
36
39
  const backendOutputSchema = z.object({ request: backendInputSchema, payload: backendPayload });
37
40
 
38
- export default (({ client }) => defineMappedTool({
41
+ export default (({ client, access }) => defineMappedTool({
39
42
  name: "search-pea-taxa",
40
- access: "public",
43
+ ...access,
41
44
  description: "Search iNaturalist's public taxon catalogue for pea species.",
42
45
  inputSchema,
43
46
  outputSchema,
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
4
4
  import { serveEmseepea } from "@emseepea/server";
5
+ import { insecureTestAuthentication, startEmseepea } from "@emseepea/testing";
5
6
  import { createBackendExample } from "../dist/app.js";
6
7
  import { inaturalistFixture } from "../test-support/inaturalist-fixture.mjs";
7
8
 
@@ -113,3 +114,21 @@ test("the API-backed example checks and passes through selected iNaturalist valu
113
114
  await running.close();
114
115
  }
115
116
  });
117
+
118
+ test("the same template composes protected access and observability", async (t) => {
119
+ const events = [];
120
+ const permissions = ["taxa:search"];
121
+ const app = await createBackendExample(
122
+ { get: async () => inaturalistFixture },
123
+ {
124
+ access: { access: "protected", requiredScopes: permissions },
125
+ authentication: insecureTestAuthentication(permissions),
126
+ observability: [{ id: "test-log", emit: (event) => events.push(event) }],
127
+ },
128
+ );
129
+ const running = await startEmseepea(t, app);
130
+ const client = await running.connect("test-token");
131
+ const result = await client.callTool({ name: "search-pea-taxa", arguments: { query: "pea" } });
132
+ assert.equal(result.isError, false);
133
+ assert.ok(events.some(({ capability }) => capability === "search-pea-taxa"));
134
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emseepea/create-api-backed-server",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Create an Em See Pea server backed by a public web API.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,9 +18,9 @@
18
18
  "prepack": "npm run build:initializer"
19
19
  },
20
20
  "devDependencies": {
21
- "@emseepea/server": "0.3.3",
21
+ "@emseepea/server": "0.4.0",
22
22
  "zod": "4.4.3",
23
- "@emseepea/testing": "0.5.2",
23
+ "@emseepea/testing": "0.6.1",
24
24
  "@modelcontextprotocol/client": "2.0.0",
25
25
  "@types/node": "24.13.3",
26
26
  "typescript": "6.0.3",