bc-webclient-mcp
Version:
Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server
56 lines • 2.08 kB
JavaScript
/**
* Current BC Session State Resource
*
* Provides introspection into active BC sessions and open pages.
* This resource helps AI assistants understand the current state of the MCP server.
*/
import { ok, err } from '../core/result.js';
import { InternalError } from '../core/errors.js';
import { SessionStateManager } from '../services/session-state-manager.js';
/**
* BCSessionStateResource exposes the current state of BC sessions.
*/
export class BCSessionStateResource {
logger;
uri = 'bc://session/current';
name = 'Current BC Session State';
description = 'Active sessions, open pages, and pageContextIds for the current MCP server process.';
mimeType = 'application/json';
constructor(logger) {
this.logger = logger;
}
/**
* Reads the current session state.
* @returns JSON snapshot of all sessions
*/
async read() {
try {
this.logger?.debug('Reading BC session state');
const manager = SessionStateManager.getInstance(this.logger);
const snapshot = manager.getSnapshot();
// Add metadata
const result = {
timestamp: new Date().toISOString(),
sessionCount: manager.getSessionCount(),
totalOpenPages: manager.getTotalOpenPages(),
sessions: snapshot.sessions,
};
const json = JSON.stringify(result, null, 2);
this.logger?.debug('Returning BC session state', {
sessionCount: result.sessionCount,
totalOpenPages: result.totalOpenPages,
});
return ok(json);
}
catch (error) {
this.logger?.error('Failed to read BCSessionStateResource', {
error: String(error),
});
return err(new InternalError('Failed to read BC session state resource', {
code: 'READ_SESSION_STATE_FAILED',
error: String(error),
}));
}
}
}
//# sourceMappingURL=session-current-resource.js.map