MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / elicitInput

Method elicitInput

src/server/index.ts:557–603  ·  view source on GitHub ↗

* Creates an elicitation request for the given parameters. * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`. * @param params The parameters for the elicitation request. * @param options Optional request options. * @returns The re

(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions)

Source from the content-addressed store, hash-verified

555 * @returns The result of the elicitation request.
556 */
557 async elicitInput(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise<ElicitResult> {
558 const mode = (params.mode ?? 'form') as 'form' | 'url';
559
560 switch (mode) {
561 case 'url': {
562 if (!this._clientCapabilities?.elicitation?.url) {
563 throw new Error('Client does not support url elicitation.');
564 }
565
566 const urlParams = params as ElicitRequestURLParams;
567 return this.request({ method: 'elicitation/create', params: urlParams }, ElicitResultSchema, options);
568 }
569 case 'form': {
570 if (!this._clientCapabilities?.elicitation?.form) {
571 throw new Error('Client does not support form elicitation.');
572 }
573
574 const formParams: ElicitRequestFormParams =
575 params.mode === 'form' ? (params as ElicitRequestFormParams) : { ...(params as ElicitRequestFormParams), mode: 'form' };
576
577 const result = await this.request({ method: 'elicitation/create', params: formParams }, ElicitResultSchema, options);
578
579 if (result.action === 'accept' && result.content && formParams.requestedSchema) {
580 try {
581 const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema as JsonSchemaType);
582 const validationResult = validator(result.content);
583
584 if (!validationResult.valid) {
585 throw new McpError(
586 ErrorCode.InvalidParams,
587 `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`
588 );
589 }
590 } catch (error) {
591 if (error instanceof McpError) {
592 throw error;
593 }
594 throw new McpError(
595 ErrorCode.InternalError,
596 `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`
597 );
598 }
599 }
600 return result;
601 }
602 }
603 }
604
605 /**
606 * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`

Callers 7

testElicitationFlowFunction · 0.95
index.test.tsFile · 0.80
index.test.tsFile · 0.80
mcp.test.tsFile · 0.80
getServerFunction · 0.80
mcpPostHandlerFunction · 0.80
deliverQueuedMessagesMethod · 0.80

Calls 1

getValidatorMethod · 0.65

Tested by 1

testElicitationFlowFunction · 0.76