@mcpfn/core 0.0.3 → 0.0.4

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
@@ -104,6 +104,6 @@ Use `registerResource`, `registerResourceTemplate`, and `registerPrompt` on the
104
104
 
105
105
  Task support is declared with `execution.taskSupport` and a `taskHandler`; a task-capable server must receive an official SDK `TaskStore`. `server.listRoots()`, `server.sample()`, and `server.elicit()` invoke matching client capabilities. Declare required client features in `clientRequirements` so manifests and host-profile tests can reject incompatible hosts before deployment.
106
106
 
107
- `createWebStandardHandler()` accepts the official SDK `HandleRequestOptions`, including validated `authInfo`. Use `@mcpfn/auth` to publish OAuth protected-resource metadata and produce that trusted value. In stateless mode, McpFn creates and disposes an isolated SDK server and transport for every request. Supply a cryptographically secure `sessionIdGenerator` when the server uses sampling, elicitation, or another server-to-client request that must be correlated across HTTP requests; session-enabled handlers retain their transport across the session.
107
+ `createWebStandardHandler()` accepts the official SDK `HandleRequestOptions`, including validated `authInfo`. Use `@mcpfn/auth` to publish OAuth protected-resource metadata and produce that trusted value. In stateless mode, McpFn creates and disposes an isolated SDK server and transport for every request. Attach protocol instrumentation with `configureRequestServer`; it receives the live isolated server before transport connection and runs once per request, or once per session initialization attempt. Because configuration precedes SDK request validation, a rejected attempt can invoke the hook without retaining a session. Supply a cryptographically secure `sessionIdGenerator` when the server uses sampling, elicitation, or another server-to-client request that must be correlated across HTTP requests; session-enabled handlers retain their transport across the session.
108
108
 
109
109
  See the [architecture](https://github.com/21nCo/super-functions/blob/main/mcpfn/ARCHITECTURE.md), [testing guide](https://github.com/21nCo/super-functions/blob/main/mcpfn/TESTING.md), and runnable [calculator example](https://github.com/21nCo/super-functions/blob/main/mcpfn/examples/calculator-server.ts).
package/dist/index.cjs CHANGED
@@ -1715,10 +1715,11 @@ var McpFnServer = class _McpFnServer {
1715
1715
  await this.connect(new import_stdio.StdioServerTransport());
1716
1716
  }
1717
1717
  async createWebStandardHandler(options = {}) {
1718
- if (!options.sessionIdGenerator) {
1718
+ const { configureRequestServer, ...transportOptions } = options;
1719
+ if (!transportOptions.sessionIdGenerator) {
1719
1720
  return async (request, handleOptions) => {
1720
1721
  const requestServer = new _McpFnServer(this.serverOptions);
1721
- const transport = new import_webStandardStreamableHttp.WebStandardStreamableHTTPServerTransport(options);
1722
+ const transport = new import_webStandardStreamableHttp.WebStandardStreamableHTTPServerTransport(transportOptions);
1722
1723
  this.requestServers.add(requestServer);
1723
1724
  let released = false;
1724
1725
  const release = async () => {
@@ -1728,6 +1729,7 @@ var McpFnServer = class _McpFnServer {
1728
1729
  await requestServer.close();
1729
1730
  };
1730
1731
  try {
1732
+ await configureRequestServer?.(requestServer);
1731
1733
  await requestServer.connect(transport);
1732
1734
  const response = await transport.handleRequest(request, handleOptions);
1733
1735
  return releaseAfterResponse(response, release);
@@ -1766,20 +1768,24 @@ var McpFnServer = class _McpFnServer {
1766
1768
  await requestServer.close();
1767
1769
  };
1768
1770
  transport = new import_webStandardStreamableHttp.WebStandardStreamableHTTPServerTransport({
1769
- ...options,
1771
+ ...transportOptions,
1770
1772
  onsessioninitialized: async (id) => {
1771
- await options.onsessioninitialized?.(id);
1773
+ await transportOptions.onsessioninitialized?.(id);
1772
1774
  initializedSessionId = id;
1773
1775
  sessions.set(id, { server: requestServer, transport });
1774
1776
  },
1775
1777
  onsessionclosed: async (id) => {
1776
1778
  sessions.delete(id);
1777
- this.requestServers.delete(requestServer);
1778
- await options.onsessionclosed?.(id);
1779
+ try {
1780
+ await transportOptions.onsessionclosed?.(id);
1781
+ } finally {
1782
+ await release();
1783
+ }
1779
1784
  }
1780
1785
  });
1781
1786
  this.requestServers.add(requestServer);
1782
1787
  try {
1788
+ await configureRequestServer?.(requestServer);
1783
1789
  await requestServer.connect(transport);
1784
1790
  const response = await transport.handleRequest(request, handleOptions);
1785
1791
  if (initializedSessionId) return response;