@mcp-layer/session
v1.0.1
Published
Shared MCP session wrapper used by connect and attach.
Downloads
897
Readme
@mcp-layer/session
@mcp-layer/session provides the shared Session class used by both @mcp-layer/connect and @mcp-layer/attach. A Session is the handle you pass around when layering new functionality on top of an MCP server.
Multiple packages return the same connected handle. To avoid duplication and drift, the Session class lives here and is re-exported by other packages.
Table of Contents
Usage
import { Session } from '@mcp-layer/session';Most users do not construct Session manually. Instead, create one via:
@mcp-layer/connect(remote/stdio transport)@mcp-layer/attach(in-process server instance)
Session shape
A Session instance contains:
client- MCP SDK clienttransport- the active transport (stdio or in-memory)info- client identityname- logical server namesource- source string (config path orin-memory)entry- server entry when available (otherwisenull)
Lifecycle
Always call session.close() when you are done to close the client and transport.
Common usage pattern
import { load } from '@mcp-layer/config';
import { connect } from '@mcp-layer/connect';
const config = await load(undefined, process.cwd());
const session = await connect(config, 'demo');
try {
const tools = await session.client.listTools({});
console.log(tools.tools.map((tool) => tool.name));
} finally {
await session.close();
}License
MIT
