-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package mcp | ||
|
||
// PromptOption is a function that configures a Prompt. | ||
// It provides a flexible way to set various properties of a Prompt using the functional options pattern. | ||
type PromptOption func(*Prompt) | ||
|
||
// ArgumentOption is a function that configures a PromptArgument. | ||
// It allows for flexible configuration of prompt arguments using the functional options pattern. | ||
type ArgumentOption func(*PromptArgument) | ||
|
||
// | ||
// Core Prompt Functions | ||
// | ||
|
||
// NewPrompt creates a new Prompt with the given name and options. | ||
// The prompt will be configured based on the provided options. | ||
// Options are applied in order, allowing for flexible prompt configuration. | ||
func NewPrompt(name string, opts ...PromptOption) Prompt { | ||
prompt := Prompt{ | ||
Name: name, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(&prompt) | ||
} | ||
|
||
return prompt | ||
} | ||
|
||
// WithPromptDescription adds a description to the Prompt. | ||
// The description should provide a clear, human-readable explanation of what the prompt does. | ||
func WithPromptDescription(description string) PromptOption { | ||
return func(p *Prompt) { | ||
p.Description = description | ||
} | ||
} | ||
|
||
// WithArgument adds an argument to the prompt's argument list. | ||
// The argument will be configured based on the provided options. | ||
func WithArgument(name string, opts ...ArgumentOption) PromptOption { | ||
return func(p *Prompt) { | ||
arg := PromptArgument{ | ||
Name: name, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(&arg) | ||
} | ||
|
||
if p.Arguments == nil { | ||
p.Arguments = make([]PromptArgument, 0) | ||
} | ||
p.Arguments = append(p.Arguments, arg) | ||
} | ||
} | ||
|
||
// | ||
// Argument Options | ||
// | ||
|
||
// ArgumentDescription adds a description to a prompt argument. | ||
// The description should explain the purpose and expected values of the argument. | ||
func ArgumentDescription(desc string) ArgumentOption { | ||
return func(arg *PromptArgument) { | ||
arg.Description = desc | ||
} | ||
} | ||
|
||
// RequiredArgument marks an argument as required in the prompt. | ||
// Required arguments must be provided when getting the prompt. | ||
func RequiredArgument() ArgumentOption { | ||
return func(arg *PromptArgument) { | ||
arg.Required = true | ||
} | ||
} |