Skip to main content

Class Definition

export class Scope extends ScopeEntry {
  readonly id: string;
  readonly logger: FrontMcpLogger;
  readonly entryPath: string;
  readonly routeBase: string;
  readonly ready: Promise<void>;
}

Properties

PropertyTypeDescription
idstringUnique scope identifier
loggerFrontMcpLoggerScope-specific logger
entryPathstringHTTP entry path
routeBasestringRoute prefix
readyPromise<void>Initialization promise
metadataScopeMetadataConfiguration metadata

Registry Accessors

tools

Get the tool registry.
get tools(): ToolRegistry
const tools = scope.tools.getTools();
const tool = scope.tools.findByName('my_tool');

resources

Get the resource registry.
get resources(): ResourceRegistry
const resources = scope.resources.getResources();
const templates = scope.resources.getResourceTemplates();
const resource = scope.resources.findResourceForUri('config://app');

prompts

Get the prompt registry.
get prompts(): PromptRegistry
const prompts = scope.prompts.getPrompts();
const prompt = scope.prompts.findByName('research');

agents

Get the agent registry.
get agents(): AgentRegistry
const agents = scope.agents.getAgents();
const agent = scope.agents.findByName('research-agent');

skills

Get the skill registry.
get skills(): SkillRegistry
const skills = scope.skills.getSkills();
const searchResults = await scope.skills.search('code review', { topK: 5 });

providers

Get the provider registry.
get providers(): ProviderRegistry
const service = scope.providers.get(ServiceToken);

auth

Get the primary auth provider.
get auth(): FrontMcpAuth

authProviders

Get the auth registry.
get authProviders(): AuthRegistry

apps

Get the app registry.
get apps(): AppRegistry

hooks

Get the hook registry.
get hooks(): HookRegistryInterface

plugins

Get the plugin registry (if configured).
get plugins(): PluginRegistry | undefined

Service Accessors

notifications

Get the notification service.
get notifications(): NotificationService
scope.notifications.on('tool-called', (event) => {
  console.log('Tool called:', event.toolName);
});

elicitationStore

Get the elicitation store.
get elicitationStore(): ElicitationStore

eventStore

Get the event store (if configured).
get eventStore(): EventStore | undefined

skillSession

Get the skill session manager (if skills exist).
get skillSession(): SkillSessionManager | undefined

toolUI

Get the tool UI registry.
get toolUI(): ToolUIRegistry

Flow Execution

runFlow(name, input, deps?)

Execute a named flow.
runFlow<Name extends FlowName>(
  name: Name,
  input: FlowInputOf<Name>,
  deps?: Map<Token, Type>
): Promise<FlowOutputOf<Name> | undefined>
const result = await scope.runFlow('tools:call-tool', {
  request: {
    method: 'tools/call',
    params: { name: 'my_tool', arguments: { input: 'test' } },
  },
  ctx: { authInfo },
});

runFlowForOutput(name, input, deps?)

Execute a flow and assert output exists.
runFlowForOutput<Name extends FlowName>(
  name: Name,
  input: FlowInputOf<Name>,
  deps?: Map<Token, Type>
): Promise<FlowOutputOf<Name>>

registryFlows(…flows)

Register additional flows.
registryFlows(...flows: FlowType[]): Promise<void>

Accessing Scope

In Tools/Resources/Agents

@Tool({ name: 'my_tool', inputSchema: {} })
class MyTool extends ToolContext {
  async execute() {
    // Access scope
    const tools = this.scope.tools;
    const resources = this.scope.resources;

    // List other tools
    const allTools = tools.getTools();

    return { toolCount: allTools.length };
  }
}

From FrontMcpInstance

const instance = await FrontMcpInstance.createForGraph(config);
const scopes = instance.getScopes();

const scope = scopes[0];
console.log('Tools:', scope.tools.getTools().length);

From DirectClient

The scope is internal to DirectClient, accessed through its methods:
const client = await connect(config);
const tools = await client.listTools(); // Uses scope.tools internally

Usage Examples

Introspection

const instance = await FrontMcpInstance.createForGraph(config);
const [scope] = instance.getScopes();

// List all tools
scope.tools.getTools().forEach(tool => {
  console.log(`Tool: ${tool.name}`);
  console.log(`  Description: ${tool.description}`);
  console.log(`  Input: ${JSON.stringify(tool.inputSchema)}`);
});

// List all resources
scope.resources.getResources().forEach(resource => {
  console.log(`Resource: ${resource.name} - ${resource.uri}`);
});

// List all skills
scope.skills.getSkills().forEach(skill => {
  console.log(`Skill: ${skill.name}`);
  console.log(`  Tools: ${skill.tools.map(t => t.name).join(', ')}`);
});

Event Handling

const scope = instance.getScopes()[0];

// Subscribe to tool changes
scope.tools.subscribe({}, (event) => {
  console.log(`Tool ${event.kind}:`, event);
});

// Subscribe to notifications
scope.notifications.on('progress', (event) => {
  console.log(`Progress: ${event.progress}/${event.total}`);
});

Skill Sessions

const scope = instance.getScopes()[0];

if (scope.skillSession) {
  // Get allowed tools for a session
  const allowed = await scope.skillSession.getAllowedTools(sessionId);

  // Check if tool is allowed
  const canUse = await scope.skillSession.isToolAllowed(sessionId, 'my_tool');
}

Initialization Sequence

The Scope initializes in this order:
  1. Providers
  2. Hooks
  3. Flows
  4. Transport Service
  5. Elicitation Store
  6. Auth Registry
  7. Apps Registry
  8. Plugins
  9. Tools Registry
  10. Tool UI Registry
  11. Resources Registry
  12. Prompts Registry
  13. Agents Registry
  14. Skills Registry + Session Manager
  15. Notification Service
  16. Additional Flows

FrontMcpInstance

Server bootstrap

ToolRegistry

Tool registry

ResourceRegistry

Resource registry

SkillRegistry

Skill registry